好的我正在尝试这个电话:
ArrayList<NameValuePair> httpParams;
httpParams = new ArrayList<NameValuePair>();
httpParams.add(new BasicNameValuePair("name", name));
httpParams.add(new BasicNameValuePair("username", username));
httpParams.add(new BasicNameValuePair("password", password));
httpParams.add(new BasicNameValuePair("email", email));
httpParams.add(new BasicNameValuePair("gender", gender));
try {
SERVICE_URL = new URL("http://idea-app.net/android/com/ProjectCaruso/Idea/SaveUser.php");
} catch (MalformedURLException e) {
Log.i(Utils.TAG, "Login Async: MalformedURLException: " + e.toString());
e.printStackTrace();
}
String response = doUrlPost(SERVICE_URL, httpParams);
以下是它所调用的代码:
public String doUrlPost(URL url, ArrayList<NameValuePair> httpParams) {
if (url != null) {
String response = "";
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(httpParams));
writer.close();
os.close();
conn.connect();
//start listening to the stream
Scanner inStream = new Scanner(conn.getInputStream());
//process the stream and store it in StringBuilder
while(inStream.hasNextLine())
response+=(inStream.nextLine());
} catch (ProtocolException e) {
Log.i(Utils.TAG, "Login Async: ProtocolException: " + e.toString());
}
catch (IOException e) {
Log.i(Utils.TAG, "Login Async: IOException: " + e.toString());
}
return response;
} else {
return null;
}
}
public String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
boolean first = true;
for (NameValuePair pair : params)
{
if (pair.getValue() == null) {
Log.i(Utils.TAG, "Push Data: Null value pair for: " + pair.getName());
} else {
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(pair.getName(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
}
}
return result.toString();
}
这是错误:
02-12 09:37:49.366: I/PROJECTCARUSO(29457): Login Async: IOException: java.io.FileNotFoundException: http://idea-app.net/android/com/ProjectCaruso/Idea/SaveUser.php
02-12 09:37:49.366: W/System.err(29457): java.io.FileNotFoundException: http://idea-app.net/android/com/ProjectCaruso/Idea/SaveUser.php
02-12 09:37:49.366: W/System.err(29457): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
02-12 09:37:49.366: W/System.err(29457): at com.projectCaruso.idea.LoginAsyncTask.doUrlPost(LoginAsyncTask.java:108)
02-12 09:37:49.366: W/System.err(29457): at com.projectCaruso.idea.LoginAsyncTask.doInBackground(LoginAsyncTask.java:69)
02-12 09:37:49.366: W/System.err(29457): at com.projectCaruso.idea.LoginAsyncTask.doInBackground(LoginAsyncTask.java:1)
02-12 09:37:49.366: W/System.err(29457): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-12 09:37:49.366: W/System.err(29457): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-12 09:37:49.366: W/System.err(29457): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-12 09:37:49.366: W/System.err(29457): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-12 09:37:49.376: W/System.err(29457): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-12 09:37:49.376: W/System.err(29457): at java.lang.Thread.run(Thread.java:841)
答案 0 :(得分:0)
请参阅LogCat:
java.io.FileNotFoundException: http://idea-app.net/android/com/ProjectCaruso/Idea/SaveUser.php
这个网址真的存在吗?
http://idea-app.net/android/com/ProjectCaruso/Idea/SaveUser.php