2013-04-05 60 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

祝你好运!