0
我是新来的android和我有C#代码的发布请求,我想在android中执行相同。 你们能帮我吗?这里是C#代码片段。Android的发布请求为aspx
WebRequest request = WebRequest.Create("http://domani.url.com");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "©req:1©un:username©pwd:password©flag:MA©ver:1.9.20©";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
// Get the response.
using (WebResponse response = request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Response.Write(responseFromServer);
}
您想从Android应用程序调用这个服务,这是你的问题是什么? – kosa 2012-01-28 07:13:09
是的我想从android应用程序调用服务。上面的 是我在web应用中使用的C#的代码。 现在我想在android中使用相同的功能。 – 2012-01-28 10:48:20