我有这个代码在localhost上调用donNet Web服务。 Web服务取5个值并返回一个字符串..我犯了这个错误:错误HTTP请求失败,HTTP状态400 ..这里有什么问题?
公共类MainActivity扩展了Activity {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://10.0.2.2:6371/Service1.asmx";
int IDocID;
String SName,SDate,STime,SReason;
TextView txt;
private PropertyInfo AppDoctor,AppDate,AppTime,AppName,AppReason;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button sent=(Button)findViewById(R.id.button1);
txt=(TextView)findViewById(R.id.textView6);
sent.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText DocID=(EditText)findViewById(R.id.editTextDoc);
IDocID = Integer.parseInt(DocID.getText().toString());
EditText Date= (EditText)findViewById(R.id.editTextDate);
SDate = Date.getText().toString();
EditText Time=(EditText)findViewById(R.id.editTextTime);
STime = Time.getText().toString();
EditText Name=(EditText)findViewById(R.id.editTextName);
SName = Name.getText().toString();
EditText Reason=(EditText)findViewById(R.id.editTextReason);
SReason = Reason.getText().toString();
new InsertTask().execute();
}
});
}
private String doInsert(String SName,String SDate,String STime,String SReason, int IDocID ) {
String result="";
final String SOAP_ACTION = "http://tempuri.org/InsertAppointment";
final String METHOD_NAME = "InsertAppointment";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("AppDoctor",IDocID);
request.addProperty("AppDate",SDate);
request.addProperty("AppTime",STime);
request.addProperty("AppName",SName);
request.addProperty("AppReason",SReason);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
System.out.println(request);
System.out.println(envelope.toString());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
/
if(response != null)
{
String resp= response.toString();
result = resp;
txt.setText(resp);
}
}catch(SocketException ex)
{
Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
ex.printStackTrace();
txt.setText(ex.toString());
}
catch (Exception e) {
Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
e.printStackTrace();
}
return result;
}
private class InsertTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
protected void onPreExecute() {
this.dialog.setMessage("Logging in...");
this.dialog.show();
}
protected Void doInBackground(final Void... unused) {
String auth=doInsert( SName, SDate, STime, SReason, IDocID);
System.out.println(auth);
return null;// don't interact with the ui!
}
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
}
}
答案 0 :(得分:0)
尝试在SOAP_ACTION中添加“”:
final String SOAP_ACTION = "\"http://tempuri.org/InsertAppointment\"";