简体   繁体   English

HTTPS请求未到达服务器android

[英]Https request not reaching to server android

I am trying to access a HTTPS request, but When I am trying to access it from my Android app it does not reach to server but the same url is working fine from chrome http client. 我正在尝试访问HTTPS请求,但是当我尝试从我的Android应用程序访问它时,它无法访问服务器,但是从chrome http客户端可以正常使用相同的网址。

Here is my code for POST HTTP request 这是我的POST HTTP请求代码

 public String POST(String url){
    InputStream inputStream = null;
    String result = "";
    try {
        String jsonreply;
        StringBuilder builder = new StringBuilder();
        HttpClient client = getNewHttpClient();
        HttpPost httpPost = new HttpPost(url);
        Log.d(TAG, "URLS"+url);
        try {
            HttpResponse response = client.execute(httpPost);
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if (statusCode == 200) {
                HttpEntity entity = response.getEntity();
                InputStream content = entity.getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(content));
                String line;
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }
            } else {
                Log.d(TAG, "Status code"+statusCode);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();

        } catch (IOException e) {
             e.printStackTrace();
        }
        jsonreply = builder.toString();
        return jsonreply;

    } catch (Exception e) {
        Log.d("InputStream", e.getLocalizedMessage());
    }

    // 11. return result
    return result;
}

the code is always is returning statusCode 404(Not Found). 该代码始终返回statusCode 404(未找到)。 I am very sure that url is correct as I am accessing same url in my other apps too. 我非常确定网址是正确的,因为我也在其他应用程序中访问相同的网址。 I can not provide the original url but the fake but similar is this one 我无法提供原始网址,但是伪造的却与此类似

https://test.test.se/user_session.json?email=test.test%40gmail.se&password=>Test12345%21%40%23%24&brand=LGE&phonemodel=Nexus+5&os_version=4.4.4&os_type=Android

Thanks for help 感谢帮助

Pass your url to this Function.. 将您的网址传递给此函数。

public static String readFeed(String URL) { 公共静态字符串readFeed(String URL){

    StringBuilder stringBuilder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(URL);
    try {
            HttpResponse response = client.execute(httpGet);
                HttpEntity entity = response.getEntity();
                InputStream content = entity.getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(content));
                String line;
                while ((line = reader.readLine()) != null) 
                {
                    stringBuilder.append(line);
                }

    } catch (ClientProtocolException e) 
    {
        e.printStackTrace();
    } catch (IOException e)
    {
        e.printStackTrace();
    }
return stringBuilder.toString();
}

The Result is return in String format. 结果以字符串格式返回。

use this one.. try { HttpClient httpclient = new DefaultHttpClient(); 使用这个。.尝试{HttpClient httpclient = new DefaultHttpClient();

            HttpContext localcon=new BasicHttpContext();
            HttpGet httpget=new HttpGet(url1);

            HttpResponse response=httpclient.execute(httpget,localcon);
            } catch (ClientProtocolException e) {

                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM