简体   繁体   English

如何使用移动热点从Android应用(物理设备)向本地服务器发送HTTP消息

[英]How can I send http messages from android app( physical device) to my local server using mobile hotspot

what i am doing. 我在做什么。

  1. I start xampp server. 我启动xampp服务器。

  2. I make connection mobile(Micromax 117) hotspot with laptop 用笔记本电脑使连接移动(Micromax 117)热点

  3. In my device there is app from that i want to send request to local server. 在我的设备中,有一个我想向本地服务器发送请求的应用程序。 I am using local IP address(IPv4) which is display on cmd in url. 我正在使用本地IP地址(IPv4),该地址显示在url中的cmd上。

Like :- http://192.168.50.32:9090/ 像: -http : //192.168.50.32 : 9090/

Here 9090 is my port number 9090是我的端口号

code: - 代码:-

 @Override
    protected String doInBackground(String... params) {
        try {
            URL url = new URL("http://192.168.43.18:9090/");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
           connection.setRequestMethod("GET");
           connection.setDoInput(false);
           connection.setRequestProperty("Content-Type", "text/html");
            connection.setRequestProperty("Accept", "text/html");
            InputStream stream = connection.getInputStream();                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
            String br = bufferedReader.readLine();
            do {
                Log.e("Data is", br);
               // Toast.makeText(MainActivity.this,br,Toast.LENGTH_LONG).show();
            } while (br != null);
        } catch (Exception e) {
            Log.e("TAG", "doInBackground:" + e.toString());
        }
        return null;
    }

I just want to know connection is working or not But nothing Working. 我只想知道连接是否正常工作,但没有任何工作。

Thanks . 谢谢 。

If you are running in local host you need to use 10.0.2.2 or if your computer is connected to network, you need to make the server listen to your network ip address. 如果您在本地主机上运行,​​则需要使用10.0.2.2,或者如果您的计算机已连接到网络,则需要使服务器侦听网络IP地址。

try this method once 一次尝试这种方法

public String  performPostCall(String requestURL,
    HashMap<String, String> postDataParams) {

URL url;
String response = "";
try {
    url = new URL(requestURL);

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(15000);
    conn.setConnectTimeout(15000);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    conn.setDoOutput(true);


    OutputStream os = conn.getOutputStream();
    BufferedWriter writer = new BufferedWriter(
            new OutputStreamWriter(os, "UTF-8"));
    writer.write(getPostDataString(postDataParams));

    writer.flush();
    writer.close();
    os.close();
    int responseCode=conn.getResponseCode();

    if (responseCode == HttpsURLConnection.HTTP_OK) {
        String line;
        BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
        while ((line=br.readLine()) != null) {
            response+=line;
        }
    }
    else {
        response="";    

    }
} catch (Exception e) {
    e.printStackTrace();
}

return response;
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用互联网连接的情况下将android物理应用中的http消息发送到本地服务器? - How can I send http messages from android app( physical device) to my local server without using internet connection? 如何使用 http 将 Android 中的文件从移动设备发送到服务器? - How do I send a file in Android from a mobile device to server using http? Xamarin应用(Android)无法从物理设备访问本地网络中的mongodb服务器 - Xamarin app (Android) can't access mongodb server in local network from physical device(s) 如何将文件从服务器发送到Android应用程序? - How I can send a file from my server to an Android app? 我将如何从我的 esp8266 模块硬件向 android 发送推送消息? 手机不安装app,可以使用内部服务吗? - How would I send push messages to android from my hardware which is esp8266 module? Without installing app in mobile, can I use internal services? 如何从我的物理 Android 设备访问我的本地主机? - How can I access my localhost from my physical Android device? 如何在 Android Studio 中将我的物理设备作为模拟器运行? - How can I run my physical device as an emulator in Android studio? 为什么我无法通过WIFI从我的android设备向本地网络上的计算机发送http请求 - Why am I Not able to send http request over WIFI to a machine on the local network from my android device 如何在Android热点之外访问本地服务器上的页面 - How to access a page on my local server outside my android hotspot 如何从应用程序内部通过电子邮件发送android设备的日志文件? - How can I send the log file of the android device via email from inside my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM