Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android上使用Wordpress API上传图像?_Android_Wordpress_Image_Api_Rest - Fatal编程技术网

如何在Android上使用Wordpress API上传图像?

如何在Android上使用Wordpress API上传图像?,android,wordpress,image,api,rest,Android,Wordpress,Image,Api,Rest,我在android中使用wordpress API上传图像时遇到问题。不幸的是,我无法理解如何设置主体(或相关代码)。每次我尝试时,就会出现错误503。我确信服务器或与连接有关的代码没有问题,因为在加载映像之前,它会执行其他操作。不幸的是,对于Android,我还没有找到多少可以帮助我的东西。我试图编辑像“source\u url”、“file”这样的标签,但什么也没有。对于标题,我输入了如上所述的内容处置(如果我错了,它将返回一个错误,然后是服务器和连接代码正常的另一个证明)。不幸的是,现在我

我在android中使用wordpress API上传图像时遇到问题。不幸的是,我无法理解如何设置主体(或相关代码)。每次我尝试时,就会出现错误503。我确信服务器或与连接有关的代码没有问题,因为在加载映像之前,它会执行其他操作。不幸的是,对于Android,我还没有找到多少可以帮助我的东西。我试图编辑像“source\u url”、“file”这样的标签,但什么也没有。对于标题,我输入了如上所述的内容处置(如果我错了,它将返回一个错误,然后是服务器和连接代码正常的另一个证明)。不幸的是,现在我没有更多的想法;所以我请求帮助我下一步能做什么。我保留返回错误503的当前代码。谢谢你的关注

            HttpParams httpParams = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
            HttpConnectionParams.setSoTimeout(httpParams, 10000);

            DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
            HttpEntity httpEntity = null;
            HttpResponse httpResponse = null;

            HttpPost httpPost = null;

            httpPost = new HttpPost("http://Worpress/wp-json/wp/v2/media");

            JSONObject object = new JSONObject();

            try {
                File file = new File(pathImage);

                object.put("title", "IMAGE");
                object.put("file", file);

                httpPost.setHeader("Authorization", "Bearer" + token);
                httpPost.setHeader("Content-Type", "image/png");
                httpPost.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");

                AbstractHttpEntity entity = new ByteArrayEntity(object.toString().getBytes("UTF8"));
                entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                httpPost.setEntity(entity);
                httpResponse = httpClient.execute(httpPost);

 
                InputStream is = httpEntity.getContent();

      
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append("\n");
                }
                is.close();
                System.out.println(sb.toString());

            } catch (JSONException | UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }