我想審查一項交易。所以我想發佈一個請求。有人可以幫我在張貼有6個參數發送請求wp7
請求Web服務是:http://www.xxxxxx.in/rest/rate
參數是:用戶名,電子郵件,評級,評論,dealId,鑰匙,手機號碼
我想審查一項交易。所以我想發佈一個請求。有人可以幫我在張貼有6個參數發送請求wp7
請求Web服務是:http://www.xxxxxx.in/rest/rate
參數是:用戶名,電子郵件,評級,評論,dealId,鑰匙,手機號碼
的RestSharp庫給你一個簡單的方法來做休息請求......他們的頭版也有很多的例子!
我會嘗試這樣的事情:
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);
}
有例如:
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