0
我想獲得這樣的字符串響應:問題與HttpRequest的在C#中的Windows Phone 8.1
public async Task<string> CheckConnection(){
//Declarations of Variables
string result = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContinueTimeout = 4000;
request.Credentials = CredentialCache.DefaultNetworkCredentials;
//Add headers to request
request.Headers["Type"] = "CHECK";
request.Headers["Device"] = "1";
request.Headers["Version"] = "0.000";
request.Headers["Os"] = "WindowsPhone";
HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
if (response.StatusCode == HttpStatusCode.OK)
{
//To obtain response body
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse, Encoding.UTF8);
result = streamRead.ReadToEnd();
streamRead.Dispose();
}
return result;
}
public async Task<string> SizeFit()
{
//Declarations of Variables
string result = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
//Add headers to request
request.Headers["Type"] = "SIZEFIT";
request.Headers["Device"] = "1";
request.Headers["Version"] = "0.000";
request.Headers["Os"] = "WindowsPhone";
HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
if (response.StatusCode != null)
{
//To obtain response body
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse, Encoding.UTF8);
result = streamRead.ReadToEnd();
streamRead.Dispose();
}
return result;
}
當我使用這個通用功能獲得1真正的連接和尺寸,但始終返回1作爲syze當我的拉鍊有大小的4K ...
public async Task<string> doSync()
{
//Declaration of variables
string response = await CheckConnection();
//When is 1, the checkConnection will connect then request Size of zip!
if (response == "1")
{
response = await SizeFit();
}
return response;
}
任何一個可以幫助我嗎?提前致謝。