CURL响应不同于从浏览器发送的请求的响应 [英] CURL response different than response to request sent from browser

查看:179
本文介绍了CURL响应不同于从浏览器发送的请求的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过PHP和命令行使用CURL提交表单。来自服务器的响应包含null内容(以下发布的标头)。



当通过浏览器提交相同的URL时,响应包含正确的webapge。 / p>

已尝试通过POST和GET通过以下命令行curl标志-d-F和-G提交CURL请求参数。 p>

如果查询字符串参数用-d标志发布,则结果头是:



HTTP / 1.1 302暂时移动

日期:Thu,2011年6月2日21:41:54 GMT

服务器:Apache

Set-Cookie:JSESSIONID = DC5F435A96A353289F58593D54B89570;路径= / XXXXXXX

P3P:CP =CAO PSA我们

位置: http://www.XXXXXXXX.com/

Content-Length:0

连接:关闭

Content-Type:text / html; charset = UTF-8

Set-Cookie:XXXXXXXXXXXXXXXX = 1318103232.20480.0000; path = /






如果查询字符串参数用-F标志发布, :



HTTP / 1.1 100继续



HTTP / 1.1 500内部伺服器错误

日期:Thu,2011年6月2日21:52:54 GMT

服务器:Apache

Content-Length:1677

连接:关闭

Content-Type:text / html; charset = utf-8

Set-Cookie:XXXXXXXXXXXXXX = 1318103232.20480.0000; path = /

Vary:接受编码


  ; html>< head>< title> Apache Tomcat / 5.5.26  - 错误报告< / title>< style><! -  H1 {font-family:Tahoma,Arial,sans-serif; color:white ; background-color:#525D76; font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif; color:white; background-color:#525D76; font-size:16px;} H3 {font -family:Tahoma,Arial,sans-serif; color:white; background-color:#525D76; font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif; color:black; :white;} B {font-family:Tahoma,Arial,sans-serif; background:white; color:#525D76;}} {font-family:Tahoma,Arial,sans-serif; black; font-size:12px;} A {color:black;} Aname {color:black;} HR {color:#525D76;}  - >< / style> < / head>< body>< h1> HTTP状态500  - < / h1>< HR size =1noshade =noshade>< p>< b> type< / b>异常报告< / p>< p>< b>消息< / b> < u>< / u>< / p>< p>< b>说明< / b> < p>< p>< b>例外< / b>< p>< < pre> javax.servlet.ServletException:Servlet执行抛出异常< br> 
< / pre>< / p>< p>< b>根原因< / b> < pre> java.lang.NoClassDefFoundError:com / oreilly / servlet / multipart / MultipartParser< br>
com.corsis.tuesday.servlet.mp.MPRequest。< init>(MPRequest.java:27)< br>
com.corsis.tuesday.servlet.mp.MPRequest。< init>(MPRequest.java:21)< br>
com.corsis.tuesday.servlet.TuesdayServlet.doPost(TuesdayServlet.java:494)< br>
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)< br>
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)< br>
< / pre>< / p>< p>< b>注意< / b> < u>< u>根本原因的完整堆栈跟踪在Apache Tomcat / 5.5.26日志中可用。< / p>< HR size =1noshade =noshade> ; h3> Apache Tomcat / 5.5.26< / h3>< / body>< / html>

问题:


  1. 根据CURL请求的性质,可能会导致服务器响应不同。


  2. 如何通过CURL成功提交请求? / p>



解决方案

HTTP / 1.1 100继续



我有与此标题相关联的问题。有些服务器根本不理解它。尝试此选项以覆盖Expect标头。



curl_setopt($ curl_handle,CURLOPT_HTTPHEADER,array('Expect:'));


Attempting to submit a form with CURL, both via PHP and the command line. The response from the server consists of null content (the headers posted below).

When the same URL is submitted via a browser, the response consists of a proper webapge.

Have tried submitting the CURL request parameters via POST and GET via each of the following command line curl flags "-d" "-F" and "-G".

If the query string parameters are posted with "-d" flag, resulting header is:

HTTP/1.1 302 Moved Temporarily
Date: Thu, 02 Jun 2011 21:41:54 GMT
Server: Apache
Set-Cookie: JSESSIONID=DC5F435A96A353289F58593D54B89570; Path=/XXXXXXX
P3P: CP="CAO PSA OUR"
Location: http://www.XXXXXXXX.com/
Content-Length: 0
Connection: close
Content-Type: text/html;charset=UTF-8
Set-Cookie: XXXXXXXXXXXXXXXX=1318103232.20480.0000; path=/


If the query string parameters are posted with "-F" flag, the resulting header is:

HTTP/1.1 100 Continue

HTTP/1.1 500 Internal Server Error
Date: Thu, 02 Jun 2011 21:52:54 GMT
Server: Apache
Content-Length: 1677
Connection: close
Content-Type: text/html;charset=utf-8
Set-Cookie: XXXXXXXXXXXXXX=1318103232.20480.0000; path=/
Vary: Accept-Encoding

<html><head><title>Apache Tomcat/5.5.26 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: Servlet execution threw an exception<br>
</pre></p><p><b>root cause</b> <pre>java.lang.NoClassDefFoundError: com/oreilly/servlet/multipart/MultipartParser<br>
    com.corsis.tuesday.servlet.mp.MPRequest.<init>(MPRequest.java:27)<br>
    com.corsis.tuesday.servlet.mp.MPRequest.<init>(MPRequest.java:21)<br>
    com.corsis.tuesday.servlet.TuesdayServlet.doPost(TuesdayServlet.java:494)<br>
    javax.servlet.http.HttpServlet.service(HttpServlet.java:710)<br>
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)<br>
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.5.26</h3></body></html>

Questions:

  1. What might cause a server to respond different depending on the nature of the CURL request.

  2. How to successfully submit request via CURL?

解决方案

HTTP/1.1 100 Continue

I had problems associated with this header before. Some servers simply do not understand it. Try this option to override Expect header.

curl_setopt( $curl_handle, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

这篇关于CURL响应不同于从浏览器发送的请求的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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