android - Send POST request over Mobile Data -


i developing android app sends , receives data python server hosted in pythonanywhere using http requests , json.

the application working perfect via wifi problem occurs when use via mobile data. data coming server requests works post , delete request not appear send or otherwise work.

i don't know whether problem is

  1. free server
  2. untrusted app
  3. permissions

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) {          inputstream inputstream = null;         string result = "";         try {             httpclient httpclient = new defaulthttpclient();             httppost post = new httppost(params[0]);             stringentity se = new stringentity(params[1]);             post.setentity(se);             post.setheader("accept", "application/json");             post.setheader("content-type", "application/json");             httpresponse httpresponse = httpclient.execute(post);             inputstream = httpresponse.getentity().getcontent();             if(inputstream != null)                 result = convertinputstreamtostring(inputstream);             else                 result = "did not work!";         } catch (exception e) {             log.i("[ error stream ]", e.tostring());         }          return result;     }      @override     abstract public void onpostexecute(string result);  } 

requestaddnewstory.java

import org.json.jsonexception; import org.json.jsonobject;  import android.app.activity; import android.content.context; import android.content.intent; import android.widget.button; import android.widget.toast;  import com.shortstory.activities.addhashtag; import com.shortstory.api.postrequest;  public class requestaddnewstory extends postrequest {      context context ;     button addhashtag ;      public requestaddnewstory(context context , button addhashtag)     {         this.context = context ;         this.addhashtag = addhashtag ;     }      @override     public void onpostexecute(string result) {          jsonobject json;         try {             json = new jsonobject(result);             string s = json.getstring("message");             if (s.equals("done")) {                 toast.maketext(context,"now add hashtags", toast.length_long).show();                intent addhashtag = new intent(context , addhashtag.class);                context.startactivity(addhashtag);                ((activity) context).finish();             }else             {                 addhashtag.setenabled(true);                 toast.maketext(context,"can't add story", toast.length_long).show();             }         } catch (jsonexception e) {             e.printstacktrace();         }      }  } 

when request send

json.accumulate("user_name", "mkm"); json.accumulate("title", "hello"); json.accumulate("body", "hello all"); json.accumulate("img", " "); requestaddnewstory rans = new requestaddnewstory(this , addhashtag); rans.execute("http://-----.pythonanywhere.com/api/story" , json.tostring()); 

after 3 weeks of debugging , see log files of server , log cat of client i'm not found logical error happens return see pythonanywhere free server limitations found :

access external internet sites code e.g. urllib or wget

specific sites via http(s) only

i don't know point means decided use https instead of http , it's work perfect in both wifi , mobile data

json.accumulate("user_name", "mkm"); json.accumulate("title", "hello"); json.accumulate("body", "hello all"); json.accumulate("img", " "); requestaddnewstory rans = new requestaddnewstory(this , addhashtag); rans.execute("https://-----.pythonanywhere.com/api/story" , json.tostring()); 

but i'm still don't know if pythonanywhere free server allow send requests https why http request work perfect via wifi only.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -