我可以使用Get Post這樣的網路服務。我可以在本地主機上使用它,沒有任何問題。然而,當我試圖通過一個安卓應用程式使用它時,我遇到了這個錯誤。
我需要在網路服務方面做什么樣的設定?因為我在 java 和 android 端做了很多事情,但是這個錯誤并沒有消失。
錯誤資訊:SoapFault - faultcode: 'soap:Client' faultstring: 'System.Web.Services.Protocols.SoapException: 服務器沒有識別HTTP頭SOAPAction的值。https://api.example.com/LoginAPI.
。public class YLogin extends AppCompatActivity {
編輯文本 yoneticieposta, yoneticiparola;
按鈕 yoneticiDGiris;
String Eposta, Parola, ReturnResult;
/*網路服務*/。
public static String URL="https://api.example.com/MCG-WS.asmx?WSDL" /span>;
public static String NAMESPACE="https://api.example.com";
/*Login API*/
public static String SOAP_ACTION_LOGIN="https://api.example.com/LoginAPI";
public static String METHOD_NAME_LOGIN="LoginAPI";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(s savedInstanceState)。
setContentView(R.layout.ylogin);
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
try {
SSLContext sc = SSLContext.getInstance("SSL") 。
sc.init(null, trustAllCerts, new java.security.SecureRandom())。
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())。
} catch (Exception e) {
}
try {
java.net.URL url = new URL( "https://api. example.com/MCG-WS.asmx")。)
} catch (MalformedURLException e) {
}
yoneticieposta = (EditText) findViewById(R.id.yoneticiepostaTx);
yoneticiparola = (EditText) findViewById(R.id.yoneticiparolaTx);
yoneticiDGiris = (Button) findViewById(R.id.yoneticiDGirisYapBt);
yoneticiDGiris.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Eposta = yoneticieposta.getText().toString()。
Parola = yoneticiparola.getText().toString()。
if(Eposta.isEmpty() || Parola.isEmpty()){
Toast.makeText(YLogin.this, "E-posta veya parola k?s?mlar?n? doldurun." , Toast.LENGTH_SHORT).show()。
}else{
new LoginAsyncTask().execute(Eposta, Parola)。
}
}
});
}
private class LoginAsyncTask extends AsyncTask< 字串,虛數,字串> {
@Override
protected void onPreExecute() {
super.onPreExecute()。
}
@Override
protected String doInBackground(String... strings){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_LOGIN)。
PropertyInfo infoEposta = new PropertyInfo() 。
infoEposta.setName("eposta")。
infoEposta.setType(String.class)。
infoEposta.setValue(strings[0].toString())。
request.addProperty(infoEposta)。
PropertyInfo infoParola = new PropertyInfo()。
infoParola.setName("parola"/span>)。
infoParola.setType(String.class);
infoParola.setValue(strings[1].toString())。
request.addProperty(infoParola)。
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope。 VER11)。)
envelope.dotNet =true。
envelope.setOutputSoapObject(request)。
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL)。
try {
androidHttpTransport.call(SOAP_ACTION_LOGIN, envelope)。
SoapFault error = (SoapFault)envelope.bodyIn。
System.out.println("TTTTTTTTTT錯誤資訊:"/span> error.toString())。
SoapObject result = (SoapObject)envelope.bodyIn。
if(result!=null){
ReturnResult = result.getProperty(0).toString()。
}
}
catch(Exception e){
e.printStackTrace()。
returne.toString()。
}
return ReturnResult;
}
@Override
protected void onPostExecute(String result) {
if(result.equals("ba?ar?l?"/span>)){
Intent intent = new Intent(YLogin. this, dashboard.class)。)
intent.putExtra("yoneticiEposta", Eposta)。
startActivity(intent)。
}else{
Toast.makeText(YLogin.this, "E-posta veya parolan?z yanl??, tekrar deneyin." , Toast.LENGTH_SHORT).show()。
}
}
}
}
uj5u.com熱心網友回復:
我更新了代碼的這些部分。問題解決了。
/*Web Service*/
public static String URL="https://api.example.com/MCG-WS.asmx?WSDL"。
public static String NAMESPACE="http://tempuri.org";
/*Login API*/
public static String SOAP_ACTION_LOGIN="http://tempuri.org/LoginAPI";
public static String METHOD_NAME_LOGIN="LoginAPI";
if (envelope.bodyIn instanceof SoapFault) {
SoapFault error = (SoapFault)envelope.bodyIn。
System.out.println("TTTTTTTTTTTT錯誤資訊:" error.toString())。
}
if (envelope.bodyIn instanceof SoapObject) {
SoapObject result = (SoapObject)envelope.bodyIn。
if(result!=null){
ReturnResult = result.getProperty(0).toString()。
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/316154.html
標籤:
