1

I am sending POST request (OKHttp) from android to python server.

android

public static final MediaType JSON
            = MediaType.parse("application/json; charset=utf-8");
String params="name="+Name+"&pass="+Pass;
RequestBody body = RequestBody.create(JSON, params);
Request request=new Request.Builder().url(URL).post(body).build(); //Request{method=POST, url=http://10.XX.XXX.XXX:8080/register, tag=null}
Response res=client.newCall(request).execute();

python server

@app.route('/register',methods=["GET","POST"])
def register():
    name=request.args.get('name')
    password=request.args.get('pass')

    print name   #None?
    print password  #None?
    return ''

Why is tag null, am I missing some point while setting POST params?

user3089927
  • 3,575
  • 8
  • 25
  • 33

1 Answers1

0

The parameters are not in JSON format. Try building the params as follows:

JSONObject paramsJson = new JSONObject();
object.put("name", Name);
object.put("pass", Pass);

String params = object.toString();

You'll have to surround with try/catch as well in case of a JSONException.

Tamer
  • 55
  • 3
  • 4