任何人都指导我在c#中动态传递参数。我已经分配了两个文本框,其中必须将这些文本框中的用户输入作为参数传递。如果我传递静态参数,我将收到服务器的响应。
这是我的编码。
string AuthServiceUri = "my url";
HttpWebRequest spAuthReq = HttpWebRequest.Create(AuthServiceUri) as HttpWebRequest;
spAuthReq.ContentType = "application/json";
spAuthReq.Method = "POST";
spAuthReq.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), spAuthReq);
}
void GetRequestStreamCallback(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
Stream postStream = myRequest.EndGetRequestStream(callbackResult);
string postData = "id=1234567890&keyword=otp&message=8320926"; //passing static parameters & here i need to pass the text boxes data in id and message field.
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Dispose();
myRequest.BeginGetResponse(new AsyncCallback(GetResponsetStreamCallback), myRequest);
}
非常感谢您的帮助。