2013-04-05 63 views
1

當我試圖地址欄下面的鏈接URL,回答是「OK」與Web客戶端發送URL

http://ww.exmaple.com.tr/webservices/addlead.php?first_name=" + r.Name + "&last_name=" + r.Surname + "&phone=" + r.Telephone + "&hash=" + r.HashCode 

但是,當我試圖像下面的Web客戶端鏈接,回答是「AUTH ERROR」

string URI = "http://ww.exmaple.com.tr/webservices/addlead.php"; 
string myParameters = "first_name=" + r.Name + "&last_name=" + r.Surname + "&phone=" + r.Telephone + "&hash=" + r.HashCode; 

using (WebClient wc = new WebClient()) 
{ 
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; 
    string HtmlResult = wc.UploadString(URI, myParameters); 
} 

我該如何解決這個問題?

回答

2

我想,你應該相當DownloadString代替UploadString使用(URI,myParameters)是這樣的:

string URI = "http://ww.exmaple.com.tr/webservices/addlead.php?"; 
string myParameters = "first_name=" + r.Name + "&last_name=" + r.Surname + "&phone=" + r.Telephone + "&hash=" + r.HashCode; 

URI += myParameters; 

using (WebClient wc = new WebClient()) 
{ 
try 
{ 
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; 
    string HtmlResult = wc.DownloadString(URI); 
} 
catch(Exception ex) 
{ 
    // handle error 
    MessageBox.Show(ex.Message); 
} 
} 

而當你想打開一個URL需要授權,則必須也許做兩次:

  • 先用得到的只是打開一個會話,並得到一個cookie之後
  • 使用POST從步驟1
餅乾

[編輯]找到這樣的例子:https://stackoverflow.com/a/4740851/1758762

祝你好運!