80,349
社区成员
发帖
与我相关
我的任务
分享
public static String sSQL(String SQL)
{
String MothodName = "ExecSQL";
HttpTransportSE ht = new HttpTransportSE("http://192.168.1.80/YFService.asmx?WSDL");
ht.debug = true;
// 使用SOAP1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
// 实例化SoapObject对象
SoapObject soapObject = new SoapObject("http://toeye.net/", MothodName);
soapObject.addProperty("SQLString", SQL);
envelope.bodyOut = soapObject;
// 设置与.Net提供的Web Service保持较好的兼容性
envelope.dotNet = true;
try
{
// 调用Web Service
ht.call("http://toeye.net/" + MothodName, envelope);
if (envelope.getResponse() != null)
{
// 获取服务器响应返回的SOAP消息
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject detail = (SoapObject) result.getProperty(MothodName
+ "Result");
// 解析服务器响应的SOAP消息。
return detail.toString();
}
}
catch (IOException e)
{
e.printStackTrace();
}
catch (XmlPullParserException e)
{
e.printStackTrace();
}
return null;
}
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Your_var_1", value));
nameValuePairs.add(new BasicNameValuePair("Your_var_2", value));
然后再创建你的web链接
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("your url only ex:www.google.com/abc");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpParams httpParameters = new BasicHttpParams();
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e)
{
Log.e("Loading Runnable Error in http connection :", e.toString());
}
现在检索响应流
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
}
catch (Exception e)
{
Log.e("Loading Runnable Error converting result :", e.toString());
}
现在在最终的结果中包含整个输出字符串,就取决于你如何读取数据。我使用json示例代码,希望能帮得上你啊。
JSONObject json_data = new JSONObject(result);// its a string var which contain output.
my_output_one = json_data.getString("var_1"); // its your response var form web.
my_output_two = json_data.getString("var_2");