public static String requestPost(String linkAddress, int timeout) {server returns the state is 200 which is a successful visit but why do not the server -side streaming ? flow does exist I use the phone can run , but with the simulator will not work, solving ? which setProxy () is a way to set the proxy access through a proxy
String result = null;
try {
URL url = new URL(linkAddress);
setProxy();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(timeout * 1000);
conn.connect();
int state = conn.getResponseCode();
System.out.println(state);
System.out.println(linkAddress);
if (state == HttpURLConnection.HTTP_OK) {
InputStream in = conn.getInputStream();
System.out.println("$$$$$$"+in.available());
BufferedReader reader = new BufferedReader(new InputStreamReader(in, HTTP.UTF_8));
String line = null;
while ((line = reader.readLine()) != null) {
if(result==null){
result=line;
}else{
result += line;
}
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
------ Solution ------------------------------------ --------
with equipment testing it ,
------ For reference only ---------------------- -----------------
top about it. . . . . Do not know ?
------ For reference only -------------------------------------- -
phone line simulator does not work , then use the handset testing chanting, anyway, finally, on the cell phone , not a simulator run .
------ For reference only ---------------------------------- -----
problem is that I do not have android phone. . . . . And this little bug module now points assigned my head how to do this ? Connect stream how successful it may be empty . . . .
------ For reference only -------------------------------------- -
you can take a look at your normal network simulator
------ For reference only ----------------------- ----------------
all functions are normal int state = conn.getResponseCode ();
state = 200
------ For reference only -------------------------- -------------
top back up to people seeking answers
------ For reference only ---------- -----------------------------
LZ, did you solve this problem , ah, my problem with you on the contrary, I simulation can obtain data on the phone not return code is 200
can tell me what is the reason you
------ For reference only -------------------------- -------------
I also get inputstream flow ah
------ For reference only ------------ ---------------------------
setProxy (); inside it ?
没有评论:
发表评论