980228 - 如何通过curl获得部分响应? [英] 980228 - how to get a portion of the response by curl?

查看:65
本文介绍了980228 - 如何通过curl获得部分响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过curl获取网址会导致无限响应。当我在浏览器中打开URL时,将开始无限的文件下载。该url属于相机,其通知相机上发生的事件,如运动检测等。但它不是一个请求/一个响应的形式。它采用一个请求/无限响应的形式。为此,我需要剪切输出以获得--boundary之间的一段。除了描述我给出了一个例子:

Fetching a url by curl causes an unlimited response. When I open the url in the browser, an endless file download will start. The url belongs to a camera which informs about events which occurs on the camera like motion detection and so on. But it's not in the form of one-request/one-response. It's in the form of one-request/unlimited-response. For this, I need to cut the output to get just a segment between "--boundary"'s. In addition to the description I'm giving an example:

--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 480

<EventNotificationAlert version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<ipAddress>192.168.14.227</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>b8:41:5f:02:81:45</macAddress>
<channelID>1</channelID>
<dateTime>2019-05-18T17:15:02+03:30</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
</EventNotificationAlert>
--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 480

<EventNotificationAlert version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<ipAddress>192.168.14.227</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>b8:41:5f:02:81:45</macAddress>
<channelID>1</channelID>
<dateTime>2019-05-18T17:15:02+03:30</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
</EventNotificationAlert>
--boundary





我尝试过:



在介绍之后,我的问题是:如何使用curl只获取第一个边界而不要等到响应结束,因为它永远不会结束?每当我看到第一个 - 边界时,我都需要切割。另一种解决方案是定义一个回调函数来获取url作为响应发送的所有内容并处理它并保留信息。怎么做?



What I have tried:

After this introduction, my problem is: how to use curl to get only the first boundary and don't wait until the response ends, because it never ends? I need to cut whenever I see the first "--boundary". Another solution instead of cutting is to define a callback function to fetch everything the url sends as response and process it and keep the info. How to do both?

推荐答案

引用:

网址属于相机





您需要阅读相机附带的说明。



比如,要发送什么消息来获得你想要的东西。



You need to read the instructions that came with the "camera".

Like, what "message" to send to get what you want.


这篇关于980228 - 如何通过curl获得部分响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆