且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CURL响应不同于从浏览器发送的请求的响应

更新时间:2023-02-22 10:36:33

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:' ) );