Android 安卓改造后请求不';不起作用,但在《邮递员》中起作用
今年我发现同样的问题 但我无法解决它 我是格雷德尔Android 安卓改造后请求不';不起作用,但在《邮递员》中起作用,android,node.js,post,retrofit2,Android,Node.js,Post,Retrofit2,今年我发现同样的问题 但我无法解决它 我是格雷德尔 compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.okhttp3:okhttp:3.8.0' compile 'com.google.code.gson:gson:2.8.0' 这是我在android中发布请求的代码 static final S
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'com.google.code.gson:gson:2.8.0'
这是我在android中发布请求的代码
static final String URL = "http://localhost:3000/";
public void map(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Map map = new HashMap();
map.put("gender", UserSex);
map.put("age", UserAge);
map.put("name", UserName);
map.put("password", UserPw);
map.put("email", UserEmail);
GitHubService gitHubService = retrofit.create(GitHubService.class);
Call<RetrofitRepo> call = gitHubService.getUserItem(map);
call.enqueue(new Callback<RetrofitRepo>() {
@Override
public void onResponse(Call<RetrofitRepo> call, Response<RetrofitRepo> response) {
try {
RetrofitRepo repoList = response.body();
String message = repoList.getmessage();
String token = repoList.gettoken();
if (message.equals("registered successfully")) {
Intent intent = new Intent(UserEnroll.this, LoginActivity.class);
startActivity(intent);
Toast.makeText(context, "register success.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "register failed.", Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onFailure(Call<RetrofitRepo> call, Throwable t) {
}
});
}
我要求用邮递员,结果成功了
http://localhost:3000/api/auth/register
{
"email": "test6@google.com",
"password": "abc123@",
"name": "user",
"age": "18",
"gender": "F"}
POST/api/auth/register 409 13.393 ms-26或
POST/api/auth/register 200 15.064 ms-51它在节点中响应
但在我的安卓应用程序上使用改型后,它就不起作用了
并且没有在节点中响应,您需要在基本URL中使用计算机或笔记本电脑的IP地址
static final String URL = "http://yourIPAddress:3000/";
例如:
静态最终字符串URL=“”
在js文件中,尝试访问是否可以共享日志中的内容?尝试在@POST(“api/auth/register”)中使用@Body调用getUserItem(@Body RequestBody选项);你得到了什么回应?任何像400这样的响应代码…你能说明你是如何在PostMan(span)中进行API调用的吗?对我来说,这是文件大小的问题,请看我也使用了它,但它的结果是相同的。你在你的menifest文件中添加了INTERNET权限了吗?是的,我也加了,但它不起作用。我检查了1。是服务器在线2。URL是正确的3。我没有使用emulator,我尝试了我的ip,但它不工作。。谢谢你的建议。如果您知道其他解决方案,请告诉我me@Jshin打开浏览器(推荐使用Chrome)并键入“”。如果可以访问,请检查改装呼叫。否则设备无法创建到服务器的连接。这是为了检查设备是否正确连接到服务器。请始终使用系统的iPAddress而不是localhost。并通过添加入站来转动防火墙ad,确保端口为扩展连接打开law@Jshin可能是您的防火墙阻止了外部请求。用上面的方法检查一下,非常感谢!我关闭了窗口防火墙,防病毒和我重启服务器它的工作!非常感谢你,兄弟!
http://localhost:3000/api/auth/register
{
"email": "test6@google.com",
"password": "abc123@",
"name": "user",
"age": "18",
"gender": "F"}
static final String URL = "http://yourIPAddress:3000/";
app.get('/test',function(req,res){
res.send(Hello This is a Test);
});