before, I have database MySQL offline in my phpmyadmin (i using xampp). I can get and post(insert) request from my android device or emulator. The url is simple, like 'localhost/cek_user' oh, i using json for parsing data to php.
and then I decide to make it online, now I must change the whole url in my program to 'http://kun-bfashion.com/cek_user' the problem is in here.
I can get like username, password, and more with this code, I just call it in my class:
public String sendGetRequest(String reqUrl){
HttpClient httpClient;
HttpGet httpGet = new HttpGet(serverUri+"/"+reqUrl);
InputStream is = null;
StringBuilder stringBuilder = new StringBuilder();
try {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 3000);
HttpConnectionParams.setSoTimeout(params, 3000);
httpClient = new DefaultHttpClient(params);
Log.d(TAG, "executing...");
HttpResponse httpResponse = httpClient.execute(httpGet);
StatusLine status = httpResponse.getStatusLine();
if(status.getStatusCode() == HttpStatus.SC_OK && httpResponse != null){
/* mengambil response string dari server */
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
while((line = reader.readLine()) != null){
stringBuilder.append(line+"\n");
}
is.close();
}
} catch (Exception e) {
//Log.d(TAG, e.getMessage());
}
return stringBuilder.toString();
}
serverUri and reqUrl is my site, I just setting it to static 'http://kun-bfashion.com, and reqURL is like 'cek_user'. i use that code for login, get data from server and many more.
but when i want to post like registration user, its showing toast "save data problem", i use this code for post to web service
public int sendPostRequest(User user, String url){
int replyCode = 99;
HttpClient httpClient;
HttpPost post = new HttpPost(this.serverUri+"/"+url);
List<NameValuePair> value = new ArrayList<NameValuePair>();
/* menambahkan parameter ke dalam request */
value.add(new BasicNameValuePair("id_user", user.getId_User().toString()));
value.add(new BasicNameValuePair("username", user.getUsername()));
value.add(new BasicNameValuePair("nama_user", user.getNamaUser()));
value.add(new BasicNameValuePair("email_user", user.getEmailUser()));
value.add(new BasicNameValuePair("password_user",user.getPasswordUser()));
try {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 3000);
HttpConnectionParams.setSoTimeout(params, 3000);
httpClient = new DefaultHttpClient(params);
post.setEntity(new UrlEncodedFormEntity(value));
Log.d(TAG, "executing post...");
HttpResponse httpResponse = httpClient.execute(post);
StatusLine status = httpResponse.getStatusLine();
if(status.getStatusCode() == HttpStatus.SC_OK){
Log.d(TAG, "submitted sucessfully...");
replyCode = status.getStatusCode();
}
} catch (IOException e) {
Log.d(TAG, e.getMessage());
}
return replyCode;
}
The Error is showing Toast "Save Data Problem", but before in my offline database (localhost) i can insert post and get without no error.
this is my LogCat when i press registrastion button:
03-15 08:19:33.032: I/System.out(23214): ex:org.apache.http.NoHttpResponseException: The target server failed to respond
03-15 08:19:33.032: I/System.out(23214): retry3
03-15 08:19:33.033: I/System.out(23214): [socket][13] connection /66.85.138.130:80;LocalPort=53906(3000)
03-15 08:19:33.033: I/System.out(23214): [CDS]connect[/66.85.138.130:80] tm:3
03-15 08:19:33.034: D/Posix(23214): [Posix_connect Debug]Process com.koenb_fashion_fix :80
03-15 08:19:33.056: I/System.out(23214): [socket][/192.168.1.111:53906] connected
03-15 08:19:33.056: I/System.out(23214): [CDS]rx timeout:3000
03-15 08:19:33.056: I/System.out(23214): >doSendRequest
03-15 08:19:33.058: I/System.out(23214): <doSendRequest
03-15 08:19:33.331: I/SurfaceTextureClient(23214): [STC::queueBuffer] (this:0x53ecad00) fps:50.80, dur:1023.54, max:43.97, min:3.79
03-15 08:19:33.505: I/SurfaceTextureClient(23214): [STC::queueBuffer] (this:0x53e75dd0) fps:1.97, dur:1015.42, max:508.04, min:507.38
03-15 08:19:33.523: I/System.out(23214): [CDS]close[53906]
03-15 08:19:33.524: I/System.out(23214): close [socket][/0.0.0.0:53906]
03-15 08:19:33.538: I/System.out(23214): ex:org.apache.http.NoHttpResponseException: The target server failed to respond
03-15 08:19:33.539: I/System.out(23214): retry4
03-15 08:19:33.539: I/System.out(23214): close [socket][/0.0.0.0:53906]
03-15 08:19:33.540: I/System.out(23214): close [socket][/0.0.0.0:53906]
03-15 08:19:33.540: D/ServerRequest(23214): The target server failed to respond
sorry for long post, but i don't know how to explain my problem -_-. thanks for read.
The problem is i can get from server, but i can't post