Closed looselive closed 7 years ago
Not use this peoxy server it's normal,plase help me!
My codes:
byte[] bytes = Encoding.UTF8.GetBytes("uid=&langx=zh-cn&mac=&ver=&JE=&username=" + this.Username + "&password=" + this.Password + "&checkbox=on");
var request = CreateRequest("http://xxx/login.php");
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = (long)bytes.Length;
request.Method = "POST";
request.Referer = "http://xxx/";
var stream = await request.GetRequestStreamAsync();
await stream.WriteAsync(bytes, 0, bytes.Length);
var response = await request.GetResponseAsync();
stream = response.GetResponseStream();
var streamReader = new StreamReader(stream, Encoding.UTF8);
string responseHTML = await streamReader.ReadToEndAsync();
streamReader.Dispose();
stream.Close();
response.Dispose();
request.Abort();
Put this:
var stream = await request.GetRequestStreamAsync();
await stream.WriteAsync(bytes, 0, bytes.Length);
to a using block:
using (var stream = await request.GetRequestStreamAsync()) {
await stream.WriteAsync(bytes, 0, bytes.Length);
}
Or maybe a Flush(Async) is enough, too. But "using" is better. And you should use "using" in the response stream, too.
When i post some data to a url get this err You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.