1

我想审查一笔交易。所以我想发布一个请求。有人可以帮我发布带有 6 个参数的请求吗

网络服务是:http ://www.xxxxxx.in/rest/rate

参数有:userName、email、rating、comment、dealId、key、mobile no

4

3 回答 3

1

RestSharp库为您提供了一种执行 Rest 请求的简单方法......而且他们的首页也有很多示例!

于 2012-05-07T08:21:41.787 回答
0

我会尝试这样的事情:

void Post()
{
     WebClient client = new WebClient(); 
     client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted); 
     client.Headers["Content-Type"] = "application/x-www-form-urlencoded"; 
     client.Encoding = Encoding.UTF8; 

     client.UploadStringAsync(new Uri("http://www.example.com/api/path/"), "POST", "userName=userName&email=email&rating=rating&comment=comment&dealid=dealid&key=key&mobileno=mobileno"); 
} 

void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) 
{ 
     MessageBox.Show(e.Result); 
} 
于 2012-05-07T08:23:54.380 回答
0

有例子:

string uri = "http://www.xxxxxx.in/rest/rate";

//data to post
string data = "userName={0}&email={1}&rating={2}&comment={3}&dealId={4}&key={5}&mobile={6}";
//fill data
data.Format(userName, email, ratings, comment, dealId, key, mobile);
//encode
byte[] byteArray = Encoding.UTF8.GetBytes (data);
//create request
HttpWebRequest request = WebRequest.Create(uri);
//set method
request.Method = "POST";
//set data length
request.ContentLength = byteArray.Length;
request.ContentType = "application/x-www-form-urlencoded";
//get stream and write into
Stream dataStream = request.GetRequestStream ();
dataStream.Write (byteArray, 0, byteArray.Length);

//do request    
IAsyncResult asyncResult = request.BeginGetResponse(p =>
{
    WebResponse response = request.EndGetResponse(p);
    //call callback when get response
    if (callback != null)
        callback(response.GetResponseStream());
}, null);

您需要设置回调委托Action<Stream> callback

于 2012-05-07T08:30:02.863 回答