cURL返回“处理请求时出错”

时间:2015-04-28 03:30:05

标签: php json curl

大家好!

我想通过cURLing中的XHR链接来抓取this site using SocialSite platform,但它会返回:

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

这是cURL代码:

curl "http://www.dbmanetwork.com/WebServices/PlannerFace.asmx/GetAppointments" \
  -H "Cookie: ASP.NET_SessionId=vdazkdnenkpzqjgdnjl24pz0; perfectmindmobilefeature=0" \
  -H "Origin: http://www.dbmanetwork.com" \
  -H "Accept-Encoding: gzip, deflate" \
  -H "Accept-Language: en-US,en;q=0.8,id;q=0.6,ms;q=0.4,jv;q=0.2" \
  -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36" \
  -H "Content-Type: application/json; charset=UTF-8" \
  -H "Accept: application/json, text/javascript, */*; q=0.01" \
  -H "Referer: http://www.dbmanetwork.com/8661/Office/Planner/ScheduleView?layoutType=wide&objectId=63be552d-cb71-40e7-aa6f-5289d7e766e9&viewId=2cb73398-53ff-4a9e-adda-3444fb771702&text=Book&skinId=4494e024-c590-4daa-9bfd-e14a7709d23b" \
  -H "X-Requested-With: XMLHttpRequest" \
  -H "Connection: keep-alive" \
  --data-binary "{""schedulerInfo"":{""ViewStart"":""\\/Date(1430092800000)\\/"",""ViewEnd"":""\\/Date(1430697600000)\\/"",""LocationId"":""All Locations"",""IsReadOnly"":true,""UseAppointmentLocationTimezone"":true,""ApplicationType"":2,""OrgId"":""29f8130e-ea28-4cd7-8bb0-298f753d9d17"",""ObjectViewIdCombos"":""63be552d-cb71-40e7-aa6f-5289d7e766e9.2cb73398-53ff-4a9e-adda-3444fb771702""}}" \
  --compressed -k

来自herehere的建议不起作用,因为cURL已满足所需条件(json_encodeContent-Type)。

THX!

UPDATE!

使用--verbose标志,我得到了这个结果:

* Adding handle: conn: 0x214d7e0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x214d7e0) send_pipe: 1, recv_pipe: 0
* About to connect() to www.dbmanetwork.com port 80 (#0)
*   Trying 50.112.169.144...
* Connected to www.dbmanetwork.com (50.112.169.144) port 80 (#0)
> POST /WebServices/PlannerFace.asmx/GetAppointments HTTP/1.1
> Host: www.dbmanetwork.com
> Cookie: ASP.NET_SessionId=vdazkdnenkpzqjgdnjl24pz0; perfectmindmobilefeature=0
> Origin: http://www.dbmanetwork.com
> Accept-Encoding: gzip, deflate
> Accept-Language: en-US,en;q=0.8,id;q=0.6,ms;q=0.4,jv;q=0.2
> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.
36
> Content-Type: application/json; charset=UTF-8
> Accept: application/json, text/javascript, */*; q=0.01
> Referer: http://www.dbmanetwork.com/8661/Office/Planner/ScheduleView?layoutType=wide&objectId=63be552d-cb71-40e7-aa6f-
5289d7e766e9&viewId=2cb73398-53ff-4a9e-adda-3444fb771702&text=Book&skinId=4494e024-c590-4daa-9bfd-e14a7709d23b
> X-Requested-With: XMLHttpRequest
> Connection: keep-alive
> Content-Length: 346
>
* upload completely sent off: 346 out of 346 bytes
< HTTP/1.1 500 Internal Server Error
< Cache-Control: private
< Content-Type: application/json; charset=utf-8
* Server Microsoft-IIS/8.5 is not blacklisted
< Server: Microsoft-IIS/8.5
< jsonerror: true
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< P3P: CP="CAO PSA OUR"
< Date: Tue, 28 Apr 2015 04:01:25 GMT
< Content-Length: 91
< Connection: Keep-Alive
<
{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}* Connection #0 to host www.d
bmanetwork.com left intact

2 个答案:

答案 0 :(得分:0)

似乎是目标服务器http://www.dbmanetwork.com。 3594 IN A 50.112.169.144已关闭。

salam dari jakarta:)

答案 1 :(得分:0)

首先,我要感谢@rezashamdani 他的回答并不是确切的答案,但它给了我强烈的暗示,直到我终于找到它。

他说问题出在我发送的json字符串中的"\\/Date(1430697600000)\\/"。我可能需要模拟javascript日期函数。我在其javascript file where the XHR executed中发现日期字符串是使用本地函数toAspDateFormat重新格式化的,它将"/Date(1430697600000)/"更改为"\\/Date(1430697600000)\\/"。它表明转义字符很重要。我将--data-binary从我的cURL更改为:"{""schedulerInfo"":{""ViewStart"":""\/Date(1430092800000)\/"",""ViewEnd"":""\/Date(1430697600000)\/"",""LocationId"":""All Locations"",""IsReadOnly"":true,""UseAppointmentLocationTimezone"":true,""ApplicationType"":2,""OrgId"":""29f8130e-ea28-4cd7-8bb0-298f753d9d17"",""ObjectViewIdCombos"":""63be552d-cb71-40e7-aa6f-5289d7e766e9.2cb73398-53ff-4a9e-adda-3444fb771702""}}"

现在效果很好。