我有以下代码。我知道网络请求等应该在异步调用中,但我只是想要概念证明。
using System;
using Android.App;
using Android.Os;
using Android.Widget;
using Dot42;
using Dot42.Manifest;
using System.Xml;
using System.Net;
using System.IO;
using System.Text;
[assembly: Application("dot42Application6")]
namespace dot42Application6
{
[Activity]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstance)
{
base.OnCreate(savedInstance);
SetContentView(R.Layouts.MainLayout);
string soap = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
<soap:Body><GetColorChangeCharge xmlns=""http://reps.catalystinnovations.net/"">
<password>ujnvusk</password></GetColorChangeCharge></soap:Body> </soap:Envelope>";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.someurl/service.asmx");
req.Headers.Add("SOAPAction", "http://www.someurl/GetColorChangeCharge");
req.ContentType = "text/xml; charset=utf-8";
req.Accept = "text/xml";
req.Method = "POST";
using (Stream stm = req.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(soap);
}
}
WebResponse resp = req.GetResponse();
Stream responsStream = resp.GetResponseStream();
}
}
}
我在 WebResponse resp = req.GetResponse(); 处得到一个 java.lang.Runtime 异常;我不知道问题是什么或如何解决它。