json - Android HTTP POST using loopj error -


i android beginner i'd http post jpg image onto server. using loopj library can't work.

the following code works smoothly in python:

c.setopt(pycurl.httpheader, [authheader]) c.setopt(pycurl.post, 1) data = [('image', (c.form_file, filename_tmp))] c.setopt(pycurl.httppost, data) c.perform() c.close() 

authheader header key in form of "authorization: token .......". unfortunately can't code on android work:

//http client setup     string loginstring = "*********";     string base_url = "https://www.******";     asynchttpclient client = new asynchttpclient();  //post image     try {         requestparams params = new requestparams();         params.put("image", myfile);         params.sethttpentityisrepeatable(true);         client.addheader("authorization: token ", loginstring);         client.post(base_url, params, new texthttpresponsehandler() {              @override             public void onsuccess(int i, header[] headers, string response) {                 jsonstring = response;                 log.d("onsuccess: ", jsonstring);             }              @override             public void onfailure(int statuscode, header[] headers, string response, throwable e) {                 if (statuscode == 401) {                     jsonstring = response;                     log.d("onfailure: ", jsonstring);                 }             }         });     } catch(filenotfoundexception e) {         log.d("debug", "error putting parameter (image)");     } 

i multiple errors in form of:

 w/system.err: javax.net.ssl.sslhandshakeexception:  java.security.cert.certpathvalidatorexception: trust anchor certification path not found. 

the django rest / json code looks that:

{     "name": "create api",     "description": "concrete view creating model instance.",     "renders": [         "application/json",         "text/html"     ],     "parses": [         "application/json",         "application/x-www-form-urlencoded",         "multipart/form-data"     ],     "actions": {         "post": {             "image": {                 "type": "image upload",                 "required": false,                 "read_only": false,                 "label": "image"             },             "imagelow": {                 "type": "image upload",                 "required": false,                 "read_only": false,                 "label": "imagelow"             },             "imagemed": {                 "type": "image upload",                 "required": false,                 "read_only": false,                 "label": "imagemed"             },             "imagehigh": {                 "type": "image upload",                 "required": false,                 "read_only": false,                 "label": "imagehigh"             }         }     } } 

thank , sorry if unclear, i'm new android.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -