Articles of http

使用Retrofit批量请求

我想使用Retrofit执行批量请求。 它有什么好办法,如何实现呢? 基本上我要做的是替换URL的查询部分中的一些字符(仅在URL的路径部分中使用替换块 – 使用@Path注释)。 这是我的问题的伪代码。 @GET(“/v2/multi?requests=/users/self,/venues/search?client_id={client_id}&client_secret={client_secret}&v={v}&ll={ll}&intent={intent}&limit={limit}”) ProfileSearchVenuesResponse searchVenuesAndProfiles(@ReplaceBy(“client_id”) String clientId, @ReplaceBy(“client_secret”) String clientSecret, @ReplaceBy(“v”) int version, @ReplaceBy(“ll”) String location, @ReplaceBy(“intent”) String intent, @ReplaceBy(“limit”) int limit);

将HTTP发布请求更改为HTTPS发布请求:

我有这个方法: public static String getReportMetadata (String reportId, String sessionId, String url) throws Exception{ Map jsonValues = new HashMap(); jsonValues.put(“reportID”, reportId); jsonValues.put(“sessionID”, sessionId); JSONObject json = new JSONObject(jsonValues); DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url + GET_REPORT_METADATA_ACTION); AbstractHttpEntity entity = new ByteArrayEntity(json.toString().getBytes(“UTF8”)); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, “application/json”)); post.setEntity(entity); HttpResponse response = client.execute(post); return getContent(response); } […]

java.io.IOException:BufferedInputStream在Android 2.3中关闭

以下代码在Android 1.5-2.2.1中运行良好,但它不在2.3及更高版本中。 BufferedReader rd; rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = rd.readLine()) != null){ sb.append(line); } rd.close(); stracktrace: 01-30 08:21:42.668: WARN/System.err(594): java.io.IOException: BufferedInputStream is closed 01-30 08:21:42.668: WARN/System.err(594): at java.io.BufferedInputStream.streamClosed(BufferedInputStream.java:116) 01-30 08:21:42.728: WARN/System.err(594): at java.io.BufferedInputStream.read(BufferedInputStream.java:274) 01-30 08:21:42.728: WARN/System.err(594): at org.apache.harmony.luni.internal.net.www.protocol.http.UnknownLengthHttpInputStream.read(UnknownLengthHttpInputStream.java:40) 01-30 08:21:42.758: WARN/System.err(594): at java.io.InputStreamReader.read(InputStreamReader.java:255) 01-30 08:21:42.758: […]

POST请求变为GET

我正在用Java开发Android和服务器应用程序。 服务器应用程序在Jetty上运行。 Android应用程序在同一台计算机上进行模拟。 Android应用程序向服务器发送POST请求,但服务器的处理程序将其解释为GET。 当我使用发送HTTP工具模拟POST请求时,它完美地工作(我的意思是方法的types是POST)。 这是Android应用程序的代码片段: HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout Limit HttpResponse response; // Create message JSONObject json = new JSONObject(); json.put(“request_type”, “info”); json.put(“user_name”, mEmail); // Send message and get response StringEntity se = new StringEntity(json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, “application/json”)); HttpPost post = new HttpPost(“http://10.0.2.2:8080/app”); post.setEntity(se); post.setHeader(“Accept”, “application/json”); post.setHeader(“Content-Type”, “application/json; charset=UTF-8”); […]

http post方法将空值传递给服务器

try { url= new URL(ConstantsClass.VENDOR_FOLLOW + “?UID=” +android_id+”&URL='”+resultfinal+”‘&device=android”); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod(“POST”); request = new OutputStreamWriter(connection.getOutputStream()); request.flush(); request.close(); request.write(“Hello!!!”); String line = “”; InputStreamReader isr = new InputStreamReader(connection.getInputStream()); BufferedReader reader = new BufferedReader(isr); StringBuffer sb = new StringBuffer(); while((line=reader.readLine())!=null) { sb.append(line + “&”); } response = sb.toString(); //response.getEntity().getContent(); Log.i(“Test”, “updated response: ” + […]

Android Async Http获取请求

我正在尝试实现一个AsClip的httpClient类(否则由于在我的主线程中有连接而得到exception)。 我试过这样的事情: private class execHttpAsync extends AsyncTask { public String resultString; @Override protected HttpResponse doInBackground(String… params) { String url = params[0]; HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); request.setHeader(“Content-Type”, “text/xml”); HttpResponse response; try { response = httpClient.execute(request); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) […]

使用KSOAP for android的基本HTTP身份validation

我需要使用Android来使用SOAP Web服务。 问题是在请求特定function之前,我需要使用基本的http请求来validation客户端。 你知道如何使用KSOAP做到这一点吗? 直到这一刻我尝试使用httpsTransportSE.call()的重载方法,因为它建议我可以为http连接指定其他标头 (参考: https : //github.com/mosabua/ksoap2-android/blob/master/ksoap2-j2se/src/main/java/org/ksoap2/transport/HttpTransportSE.java ) headerPropertyList.add(new HeaderProperty(“Authorization”, “Basic : dXNlcjpwYXNz”)); “cdXNlcjpwYXNz”是base 64编码的“user:pass”字符串 public List call(String soapAction, SoapEnvelope envelope, List headers) * @param headers a list of HeaderProperties to be http header properties when establishing the connection private static final String SOAP_ACTION = “someaddress/IPortReporting/GetPortStatus”; private static final String METHOD_NAME = “methodname”; […]

android httpGet问题

我正在尝试使用以下代码执行以下链接: class httpget{ HttpGet httpGet=null; public void linkexecute(){ String url=”http:////action=send&msg=new message”; httpGet= new HttpGet(url); // line 1 …. } at line 1 it is giving error “Illegal arguement exception” java.lang.IllegalArgumentException: Illegal character in query at index 77: http:////sms.json?action=send&msg=new message at java.net.URI.create(URI.java:970) at org.apache.http.client.methods.HttpGet.(HttpGet.java:75) at com.sms.login.LoginService.sendSms(LoginService.java:143) 鉴于下面给出的URL没有错误,“msg =”的单词没有间隙 String url=”http:////action=send&msg=newmessage”; 如何解决URL中单词间隙的问题?

从URL下载图像到SD卡

我正在尝试创建一个非常简单的图像下载应用程序。 我想从这个url下载所有图像到SD卡: https://www.dropbox.com/sh/5be3kgehyg8uzh2/AAA-jYcy_21nLBwnZQ3TBFAea : https://www.dropbox.com/sh/5be3kgehyg8uzh2/AAA-jYcy_21nLBwnZQ3TBFAea 此代码适用于在imageview中加载图像: package com.example.imagedownloadsample; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ImageView; import com.squareup.picasso.Picasso; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.image_download); final ImageView img = (ImageView) (findViewById(R.id.imageView1)); // File file = new File(Environment.getExternalStorageDirectory(), // “Android/data/com.usd.pop”); Picasso.with(getApplicationContext()) .load(“http://img.androidcookie.com/android/8020.photos.jpgmag.com/3456318_294166_528c960558_m.jpg”) .into(img); } } 但当我尝试这样下载图像到SD卡我最终与不幸的应用程序停止错误: package com.example.imagedownloadsample; import java.io.File; import […]

Android HttpResponse响应代码

我正在尝试获取HttpReponse的响应代码。 没有直接获取响应代码的方法。