Java 请求Android中的重定向URL
我正在尝试向服务器发送请求,并获得一个重定向URL作为响应Java 请求Android中的重定向URL,java,android,http-redirect,Java,Android,Http Redirect,我正在尝试向服务器发送请求,并获得一个重定向URL作为响应{“重定向URL”:http://192.168.1.95“}来自服务器,我想再次向重定向URL发送请求 我收到错误:到的连接http://192.168.1.95 在安卓系统中被拒绝。在iOS系统中工作正常 请帮我解决这个问题 private void Signup(final String firstname,final String lastname,String email, String password,String a
{“重定向URL”:http://192.168.1.95“}
来自服务器,我想再次向重定向URL发送请求
我收到错误:到的连接http://192.168.1.95 在安卓系统中被拒绝
。在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);
}
private void注册(最终字符串名、最终字符串名、字符串电子邮件、字符串密码、字符串操作、字符串路径){
类SignupAsync扩展了AsyncTask{
//私有对话框加载对话框;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
@凌驾
受保护的字符串doInBackground(字符串…参数){
字符串fname=params[0];
字符串lname=params[1];
字符串email=params[2];
字符串密码=参数[3];
字符串操作=参数[4];
字符串finalpath1=params[5];
InputStream=null;
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“用户名”,电子邮件));
添加(新的BasicNameValuePair(“firstname”,fname));
添加(新的BasicNameValuePair(“lastname”,lname));
添加(新的BasicNameValuePair(“密码”,password));
添加(新的BasicNameValuePair(“_action”,action));
字符串结果=null;
字符串最终路径;
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=null;
如果(finalpath1!=null){
httpPost=新的httpPost(最终路径1);
}
否则{
httpPost=新的httpPost(“http://192.168.1.122");
}
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse响应=null;
response=httpClient.execute(httpPost);
HttpEntity=null;
entity=response.getEntity();
is=entity.getContent();
BufferedReader reader=新的BufferedReader(新的InputStreamReader(is,“UTF-8”),8;
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null)
{
sb.追加(第+行“\n”);
}
结果=sb.toString();
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(不支持的编码异常e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
返回结果;
}
@凌驾
受保护的void onPostExecute(字符串结果){
字符串finalpath=结果;
if(finalpath!=null)
{
SignupAsync la1=新的SignupAsync();
la1.execute(“firstname”,“lastname”,”em@h.n“,“kkkjpass”,“REGISTERUSER”,finalpath);}
}
}
SignupAsync la=新的SignupAsync();
执行(名字、姓氏、电子邮件、密码、操作、路径);
}
您正在从仿真器中尝试此操作?那么,仿真器可能位于不同的子网中,并且找不到指定的IP地址。您是否在清单中具有Internet权限。或者检查任何损坏的清单文件。API的名称是什么?您将参数传递给哪个API?