几天来,我一直在尝试发布到服务器。但我收到一个错误的请求错误,即:
HTTP/1.1 400 Bad Request
Server: cloudflare-nginx
Date: Sat, 13 Oct 2012 14:25:32 GMT
Content-Type: text/html
Content-Length: 522
Connection: close
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare-nginx</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a pad
我的代码在这里(我在 c# 上使用了libcurl.net)
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
Thread.Sleep(400);
try
{
var curl = new Easy();
Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
curl.SetOpt(CURLoption.CURLOPT_URL, webpage);
curl.SetOpt(CURLoption.CURLOPT_HEADER, true);
curl.SetOpt(CURLoption.CURLOPT_TIMEOUT, "100");
curl.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, false);
Slist sl = new Slist();
sl.Append(String.Format("POST {0} HTTP/1.1\r\n\r\n", (new Uri(oyy.sayfa).PathAndQuery)));
sl.Append(String.Format("Host: {0}", hostname ));
sl.Append(String.Format("{0}", "Connection: keep-alive"));
sl.Append(String.Format("Content-Length: {0}", param.Length));
sl.Append(String.Format("Origin: {0}", originname));
sl.Append(String.Format("{0}", "X-Requested-With: XMLHttpRequest"));
sl.Append(String.Format("User-Agent: {0}", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4"));
sl.Append(String.Format("{0}", "Content-Type: application/x-www-form-urlencoded"));
sl.Append(String.Format("{0}", "Accept: */*"));
sl.Append(String.Format("Referer: {0}",referans));
sl.Append(String.Format("{0}", "Accept-Encoding: gzip,deflate,sdch"));
sl.Append(String.Format("{0}", "Accept-Language: en-US,en;q=0.8"));
sl.Append(String.Format("{0}", "Accept-Charset: utf-8;q=0.7,*;q=0.3*/"));
sl.Append("\r\n\r\n");
curl.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl);
curl.SetOpt(CURLoption.CURLOPT_COOKIEFILE, CookieFile);
curl.SetOpt(CURLoption.CURLOPT_COOKIEJAR, CookieFile);
curl.SetOpt(CURLoption.CURLOPT_COOKIE, "cokieee");
curl.SetOpt(CURLoption.CURLOPT_PROXY, "http://127.0.0.1:9050");
curl.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_SOCKS5);
curl.SetOpt(CURLoption.CURLOPT_VERBOSE, false);
curl.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
curl.Perform();
curl.Cleanup();
curl.GlobalCleanup();
string result = sourceContent.ToString();
----------
public Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
{
string aa = System.Text.Encoding.UTF8.GetString(buf);
this.sourceContent.Append(aa + " ");
return size * nmemb;
}
我认为这个问题是基于CURLOPT_HTTPHEADER
. 我认为sl
( SList
) 不正确,或者我错过了添加一些内容。我上面的所有信息。