当前位置: 首页 > 知识库问答 >
问题:

从移动应用程序调用localhost Web服务时出现拒绝访问错误

倪棋
2023-03-14

我正在使用IIS 7构建Web服务,以便在设备SQLite和服务器MS SQL数据库之间复制数据。Web服务是从移动浏览器执行的,在WiFi上没有问题。执行Transporte.call后,我收到拒绝访问错误。我正在尝试从三星Note Edge设备执行。

请注意,使用VB.NET,我能够从网络上的另一台计算机成功地使用Web服务的两种方法。

多谢了。

主要activity:

    import android.os.StrictMode;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.Toast;
    import org.json.JSONArray;
    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;

    public class MainActivity extends AppCompatActivity {
        private final String NAMESPACE = "http://192.168.0.2/";
        private final String URL = "http://192.168.0.2/MimsWeb/MimsWeb.asmx";
        private final String SOAP_ACTION = "MimsWeb";
        private final String METHOD_NAME = "RetrieveS";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            if (android.os.Build.VERSION.SDK_INT > 9) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);
            }
            SoapObject  request = new SoapObject(NAMESPACE,METHOD_NAME);
            request.addProperty("select * from Product","Prduct");

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);

            try {
                HttpTransportSE transporte = new HttpTransportSE(URL);
                transporte.call(SOAP_ACTION,envelope);

                SoapPrimitive resultadoXML = (SoapPrimitive)envelope.getResponse();
        //Log.e("Valor de respuesta",resultadoXML.toString());
        String resultado = resultadoXML.toString();
    }catch (Exception e){
    e.printStackTrace();
            Toast.makeText(getBaseContext(),e.getMessage().toString(),Toast.LENGTH_LONG).show();
        }

        }
    }

清单:

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

日志

    I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
    I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
    W/art: Debugger attempted to resume all threads without having suspended them all before.
    W/System.err: java.net.SocketException: socket failed: EACCES (Permission denied)
    Disconnected from the target VM, address: 'localhost:8606', transport: 'socket'

Web服务URL:

    http://192.168.0.2/MimsWeb/MimsWeb.asmx


    The following operations are supported. For a formal definition, please review the Service Description.

    InsertS
    RetrieveS

检索:

    http://192.168.0.2/MimsWeb/MimsWeb.asmx?op=RetrieveS


    Click here for a complete list of operations.

    RetrieveS

    Test

    To test the operation using the HTTP POST protocol, click the 'Invoke' button.
    Parameter   Value
    s:  
    t:  
    Invoke
    SOAP 1.1

    The following is a sample SOAP 1.1 request and response. The    placeholders shown need to be replaced with actual values.

    POST /MimsWeb/MimsWeb.asmx HTTP/1.1
    Host: 192.168.0.2
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://192.168.0.2/RetrieveS"

    <?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>
        <RetrieveS xmlns="http://192.168.0.2/">
        <s>string</s>
        <t>string</t>
        </RetrieveS>
    </soap:Body>
    </soap:Envelope>
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length

    <?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>
        <RetrieveSResponse xmlns="http://192.168.0.2/">
        <RetrieveSResult>xmlxml</RetrieveSResult>
        </RetrieveSResponse>
      </soap:Body>
    </soap:Envelope>
    SOAP 1.2

    The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.

    POST /MimsWeb/MimsWeb.asmx HTTP/1.1
    Host: 192.168.0.2
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <RetrieveS xmlns="http://192.168.0.2/">
          <s>string</s>
          <t>string</t>
        </RetrieveS>
      </soap12:Body>
    </soap12:Envelope>
    HTTP/1.1 200 OK
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <RetrieveSResponse xmlns="http://192.168.0.2/">
          <RetrieveSResult>xmlxml</RetrieveSResult>
        </RetrieveSResponse>
       </soap12:Body>
    </soap12:Envelope>
    HTTP GET

    The following is a sample HTTP GET request and response. The placeholders shown need to be replaced with actual values.

    GET /MimsWeb/MimsWeb.asmx/RetrieveS?s=string&t=string HTTP/1.1
    Host: 192.168.0.2
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>
    <DataTable xmlns="http://192.168.0.2/">xmlxml</DataTable>
    HTTP POST

    The following is a sample HTTP POST request and response. The placeholders shown         need to be replaced with actual values.

    POST /MimsWeb/MimsWeb.asmx/RetrieveS HTTP/1.1
    Host: 192.168.0.2
    Content-Type: application/x-www-form-urlencoded
    Content-Length: length

    s=string&t=string
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>
    <DataTable xmlns="http://192.168.0.2/">xmlxml</DataTable>

共有1个答案

谢和同
2023-03-14

AndroidManifest.xml中,uses-permission标记应该写在application标记之外。

清单中缺少internet权限。这就是错误的原因。

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

这是您正在尝试创建的请求。

<RetrieveS xmlns="http://192.168.0.2/">
  <s>string</s>
  <t>string</t>
</RetrieveS>

这就是创建上述请求的方式,

SoapObject  request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("s","sValue");
request.addProperty("t","tValue");
envelope.setOutputSoapObject(request);

如果希望获得响应xml,

HttpTransportSE transporte = new HttpTransportSE(URL);
transporte.debug = true;
try {
    transporte.call(SOAP_ACTION,envelope);

    String resultado = transporte.responseDump;
} catch (Exception e){
    e.printStackTrace();
    Toast.makeText(getBaseContext(),e.getMessage().toString(),Toast.LENGTH_LONG).show();
}
 类似资料:
  • 我正在一个项目中工作,目标是从amazon S3获取报告。目前,我正在尝试访问S3位置,以检查我的可用桶列表。 我在python中工作,我已经在提示符下设置了所有凭据:aws configure。 在我的python文件中,当我尝试列出我所有的bucket时: 我得到了这个错误: 回溯(最后一次调用):文件“C:\Users\bakpovo\testAmazon.py”,第3行,在s3中的buck

  • 警告:mysqli_connect():(HY000/1045):第2行C:\xampp\htdocs\netbanking\dbconnection.php中的用户'root'@'localhost'(使用密码:YES)被拒绝访问 致命错误:未捕获错误:在C:\xampp\htdocs\netbanking\dbconnection.php中调用未定义函数mysql_error():5堆栈跟踪:

  • 我对php和mySQL是完全陌生的,并且正在尝试连接到远程数据库。这是我的代码:- $result=mysql_query(“Select*FROM Constants”); while($ROW=mysql_fetch_array($result)){echo$ROW['name']; echo“ ”;} mysql_close($con); 对这个问题有什么想法吗?马特·蒂亚

  • 问题内容: 为了在具有许多参数的表单中发布AJAX表单,我使用一种解决方案:创建一个,通过POST将表单发布到其中,然后访问的内容。具体来说,我正在访问这样的内容: 我对其进行了测试,并且效果良好。 在某些页面上,我开始出现“访问被拒绝”错误。据我所知,如果iframe是从同一域提供的,则不应发生这种情况。 我很确定它以前可以正常工作。有人知道吗? 如果我不够清楚:我要发布到 同一域 。因此,这不

  • 我使用最新版本的PsExec,并以管理员身份运行执行命令提示符。我们使用PsExec v2.11 执行简单的服务器连接测试(例如从我的机器my_机器到远程_服务器) 另一个域中的另一个伙伴,它获取拒绝访问错误。 要登录到计算机的用户是域\u伙伴\用户\u伙伴。 我检查了PSExec使用的端口445和135,它们都在远程_服务器上打开。其他领域。本地计算机: 可从资源管理器访问目录: 我得到访问被拒

  • 在此处输入代码:调用ListBucket操作时出错(AccessDenied):拒绝访问 但我有一个IAM策略集,并使用aws CLI和--profile,该配置文件附带了该策略。IAM政策: