请求Android中的重定向网址

时间:2017-01-10 07:30:09

标签: java android http-redirect

我正在尝试向服务器发送请求并从服务器获取重定向URL作为响应{"redirect url":"http://192.168.1.95"},并且我想再次向重定向URL发送请求。

我在android中获得错误:the Connection to http://192.168.1.95 refused。在iOS中,它工作正常。

请帮我解决这个问题。

  private void Signup(final String firstname,final String lastname,String  email, String password,String action,String path) {
        class SignupAsync extends AsyncTask<String, Void, String>{

           // private Dialog loadingDialog;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();

            @Override
            protected String doInBackground(String... params) {
                String fname = params[0];
                String lname = params[1];
                String email = params[2];   
                String password = params[3];
                String action = params[4];
                String finalpath1=params[5];

                InputStream is = null;

                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("username", email));
                nameValuePairs.add(new BasicNameValuePair("firstname", fname));
                nameValuePairs.add(new BasicNameValuePair("lastname", lname));
                nameValuePairs.add(new BasicNameValuePair("password", password));
                nameValuePairs.add(new BasicNameValuePair("_action", action));
                String result = null;
                String finalpath; 
                try{
                     HttpClient httpClient = new DefaultHttpClient();
                     HttpPost httpPost=null;
                if (finalpath1 != null){        
                  httpPost = new HttpPost(finalpath1);
                }
                else{
                  httpPost = new HttpPost("http://192.168.1.122");          
                }
                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response=null;
                response = httpClient.execute(httpPost);                         
                HttpEntity entity = null;
                entity= response.getEntity();
                is = entity.getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                 StringBuilder sb = new StringBuilder();
                 String line = null;
                 while ((line = reader.readLine()) != null)
                    {
                       sb.append(line + "\n");
                    }
                    result = sb.toString();    
                 } catch (ClientProtocolException e) {
                     e.printStackTrace();
                 } catch (UnsupportedEncodingException e) {
                     e.printStackTrace();
                 } catch (IOException e) {
                     e.printStackTrace();
        }
                return result;
            }

     @Override
            protected void onPostExecute(String result){
                String finalpath = result;
                    if(finalpath != null)
                        {
                         SignupAsync la1 = new SignupAsync();
la1.execute("firstname","lastname","em@h.n","kkkjpass","REGISTERUSER",finalpath); }
          }
        }
        SignupAsync la = new SignupAsync();
        la.execute(firstname,lastname,email,password,action,path);
    }

0 个答案:

没有答案