我說的是POST請求,使用:爲什麼我對WebClient對象的第一次請求總是需要15秒?
WebClient wc = new WebClient();
String result = wc.UploadString("http://example.com/", "data=hello, world!");
編輯:這是現在我的實際代碼:
String result;
using (WebClient wc = new WebClient())
{
result = wc.UploadString("http://" + "pastebin.com/api_public.php", "POST", "paste_code=" + LongDataEscape(Clipboard.GetText()));
}
如果你想知道關於LongDataEscape:
public String LongDataEscape(String Str)
{
String Output = "";
int ByteCount = 32766;
if (Str.Length > ByteCount)
{
for (int i = 0; i < Str.Length; i+= ByteCount)
{
if (Str.Length - i < ByteCount)
Output += Uri.EscapeDataString(Str.Substring(i, Str.Length - i));
else
Output += Uri.EscapeDataString(Str.Substring(i, ByteCount));
}
}
else
Output = Uri.EscapeDataString(Str);
return Output;
}
我第一次執行上面這段代碼時,總是需要大約15秒(可能是10),不管我們是什麼它是,但跟隨的相同的代碼片斷是即刻。
我在想這可能會有一些設置,但我還沒有發現。
這聽起來像是在等待超時。是否有可能設置了正在嘗試使用的代理設置?我建議使用Process Monitor(http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx)來查看10-15秒內發生了什麼。 – Gabe 2010-11-07 04:19:19
@加貝我沒有做這樣的事情。我只是試過procmon,並沒有在10秒內顯示任何有趣的東西。只是沒有做任何事情... – Codecat 2010-11-07 16:29:47