我正在开发一个Android应用程序,它使用HTTP请求和JSON 从pythonanywhere托管的python服务器发送和接收数据.
该应用程序通过WIFI完美运行,但当我通过移动数据使用它时会出现问题.来自具有GET请求的服务器的所有数据都可以正常工作,但POST和DELETE请求似乎不会发送或以其他方式工作.
我不知道问题是否存在
PostRequest.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import android.os.AsyncTask;
import android.util.Log;
public abstract class PostRequest extends AsyncTask<String,Void,String> {
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
@Override
protected String doInBackground(String... params) …Run Code Online (Sandbox Code Playgroud) 我遇到了一些包含%数组参数内符号的代码.
它是什么意思,它是如何工作的?
例:
String[] name = { "a", "b", "c", "d" };
System.out.println(name[4 % name.length]);
System.out.println(name[7 % name.length]);
System.out.println(name[50 % name.length]);
Run Code Online (Sandbox Code Playgroud)
输出:
a
d
c
Run Code Online (Sandbox Code Playgroud)