Today I did a little demo using the Search API on Twitter. Create a new project and write the following test code directly in the Page_Load of the test page.
protected void Page_Load(object sender, EventArgs e)
{
string urlPost = "http://search.twitter.com/search.json";
string postData = "q=twitterapi";
UTF8Encoding encoding = new UTF8Encoding();
byte[] byteData = encoding.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlPost);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteData.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(byteData, 0, byteData.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
Response.Write("Response stream received.");
Response.Write(readStream.ReadToEnd());
response.Close();
readStream.Close();
}
Unfortunately, The error “The remote Server has returned an Error: (417) taught failed” appeared.
At first, I thought it was the “great Firewall”, but it was still the same after connecting to THE VPN, so I went online to find a solution, and finally I found the reason.
“This error can be caused by a client network environment (Don’t Support “100 continue”). Add the following to the program’s configuration file and give it a try.” The original address: http://0e2.net/post/1184.html
<configuration>
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
</configuration>
Test, success!!
Reproduced in: https://www.cnblogs.com/aimarAgt/archive/2011/08/17/2143177.html
Read More:
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- can’t set headers after they are sent
- In the HTML page request Ajax times 400 error, solve Yii submit post form 400 error, and Ajax post request 400 problem (example code)
- PHP & nbsp; built in server array
- Flask Request an extension before_request after_request errorhandler
- Error domain = nsurlerrordomain code = – 1001 “request timeout occurred in swift alamofire get request. ” UserInfo={NSUnderlyingErro
- Processing method of HTTP 411 error code
- Nginx configures different domain names to access different projects
- java.nio.charset.MalformedInputException: Input length = 1
- JSON parse error: invalid UTF-8 solution series
- Python: crawler handles strings of XML and HTML
- WSS connection server error
- stay web.xml Configure error page in
- A method of collecting JS dynamic content by PHP
- When generating a test report in HTML format, report [typeerror: a bytes like object is required, not ‘STR’]
- Error: ENOENT: no such file or directory, open ‘E:\Program Files\nodejs\tmp\upload_38b32f25bc984333c
- Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
- Ambiguous reference to member ‘dataTask(with:completionHandler:)’
- Sys.webforms.pagerequestmanagerparsererrorexception: unable to parse message received from server
- React Native: TypeError: Network request failed