月朗心惜 a月朗心惜
那年我捉住了蝉,以为捉住了整个夏天
关注数: 63 粉丝数: 61 发帖数: 5,865 关注贴吧数: 16
使用xutils插件上传出错 package com.chenshi.facerec; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import android.content.Context; import com.lidroid.xutils.HttpUtils; import com.lidroid.xutils.exception.HttpException; import com.lidroid.xutils.http.RequestParams; import com.lidroid.xutils.http.ResponseInfo; import com.lidroid.xutils.http.callback.RequestCallBack; import com.lidroid.xutils.http.client.HttpRequest.HttpMethod; public class Post { /** * @param args */ private static HttpUtils httpUtils = new HttpUtils(); private static String face_url = "http://tieba.baidu.com/mo/q/checkurl?url=http%3A%2F%2Fapicn.faceplusplus.com&urlrefer=de10d379436ddbec40ea18cee2232fa8"; protected static String api_key = "9cca626565a44ad00f2e28c43b74ed5f"; private static String api_secret = "3gqeN8HpFuDE7vShpCWx4O223wuWowa6"; private static String result; /** 将图片转换为二进制数据流 */ public static byte[] ShowImgByByte(String path) throws IOException { File file = new File(path); byte[] img = new byte[1024]; try { InputStream is = new FileInputStream(file); is.read(img); is.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return img; } public String Post(final Context context, byte[] img) { // TODO Auto-generated constructor stub result = ""; face_url += "/detection/landmark"; RequestParams params = new RequestParams(); /*出错处,报错The type org.apache.http.NameValuePair cannot be resolved. It is indirectly referenced from required .class files params.addQueryStringParameter("API_KEY", api_key ); params.addBodyParameter("KEY_API_SECRET", api_secret ); params.addBodyParameter("image", img.toString()); */ httpUtils.send(HttpMethod.POST, face_url, params, new RequestCallBack<String>() { @Override public void onFailure(HttpException arg0, String arg1) { // TODO Auto-generated method stub } @Override public void onSuccess(ResponseInfo<String> arg0) { // TODO Auto-generated method stub } }); return result; } public static void main(String[] args) { // TODO Auto-generated method stub } }
1 下一页