Tag: http post

使用response.sendRedirect方法在java中发送Post请求

我想在java中发送一个post请求。 我已经看到了使用Http Client发布请求的示例。 但我想使用sendRedirect方法。 例如, https://processthis.com/process?name = xyz&phone = 9898989898 我想使用post请求发送这些参数。 因此,任何人都不会看到这些参数,同时我需要将我的url重定向到该url,因为 response.sendRedirect(“https://processthis.com/process”);

使用HTTP POST时,SOLR查询字符串是否有大小或术语限制?

我正在使用Java来查询SOLR服务器,以查找在我感兴趣的一组已知ID中具有ID的结果。 我能想到的最好的方法是获得我感兴趣的这些结果是创建一个看起来像这样的长查询字符串: q=(item_id:XXX33-3333 OR item_id:YYY42-3445 OR item_id:JFDE-3838) 在发出请求之前,我生成了这个String, queryString ,并且我最终想要在请求中包含超过1500个这样的id。 我正在使用HTTP POST来进行查询: HttpPost post = new HttpPost(url); post.setHeader(“Content-Type”, “application/x-www-form-urlencoded; charset=utf-8”); StringEntity entity = new StringEntity(queryString, “UTF-8”); entity.setContentType(“application/x-www-form-urlencoded; charset=utf-8”); post.setEntity(entity); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(post); 如果我将查询限制为只有前1000个ID,它会成功,我会按照我的预期得到结果。 但是,如果我将查询增加到包含我真正感兴趣的所有1500,我会得到一个HTTP 400响应代码,其中包含以下错误: HTTP/1.1 400 org.apache.lucene.queryParser.ParseException: Cannot parse ‘[my query here…] 在SOLR查询中,我可以一起使用OR的数量是否有限制? 当我超过1000时,还有另一个原因可能会失败吗? 我已经进行了实验,它在1024左右失败了(我的ID几乎都是相同的长度)所以它似乎暗示有一个字符或术语限制。 或者,如果有人对如何以另一种更智能的方式检索我正在寻找的物品有一个很好的建议,我很乐意听到它。 我的备份解决方案只是查询所有项目的SOLR,解析结果,并使用属于我感兴趣的集合的那些。我宁愿不这样做,因为数据源可能有数万个项目,而且效率低下。

Android:无法发送httppost

我一直在试图弄清楚如何在Android中发送post方法。 这就是我的代码的样子: public class HomeActivity extends Activity implements OnClickListener { private TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView) findViewById(R.id.text); Button button = (Button)findViewById(R.id.button); button.setOnClickListener(this); } @Override public void onClick(View view) { HttpPost httpMethod = new HttpPost(“http://www.example.com/”); httpMethod.addHeader(“Accept”, “text/html”); httpMethod.addHeader(“Content-Type”, “application/xml”); AndroidHttpClient client = AndroidHttpClient.newInstance(“Android”); String result = null; try […]

JAVA中带有JSON字符串的HTTP POST请求

我必须使用我已生成的JSON字符串发出http Post请求。 我尝试了两种不同的方法: 1.HttpURLConnection 2.HttpClient 但我从他们两个得到了相同的“不需要的”结果。 到目前为止,我的代码与HttpURLConnection是: public static void SaveWorkflow() throws IOException { URL url = null; url = new URL(myURLgoeshere); HttpURLConnection urlConn = null; urlConn = (HttpURLConnection) url.openConnection(); urlConn.setDoInput (true); urlConn.setDoOutput (true); urlConn.setRequestMethod(“POST”); urlConn.setRequestProperty(“Content-Type”, “application/json”); urlConn.connect(); DataOutputStream output = null; DataInputStream input = null; output = new DataOutputStream(urlConn.getOutputStream()); /*Construct the POST data.*/ String […]

无法将AsyncTask的响应发布到MainActivity

我是Android应用程序开发的新手。 当用户点击按钮时,请查找我的AsyncTask代码以连接URL。 package in.mosto.geeglobiab2bmobile; import java.io.IOException; import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import android.os.AsyncTask; public class OnbuttonclickHttpPost extends AsyncTask { @Override protected String doInBackground(String… params) { byte[] result = null; String str = “”; // […]

curl POST没有传递URL参数

这是我的java代码: @POST @Path(“/sumPost”) @Produces(MediaType.TEXT_PLAIN) public String sumPost(@QueryParam(value = “x”) int x, @QueryParam(value = “y”) int y) { System.out.println(“x = ” + x); System.out.println(“y = ” + y); return (x + y) + “\n”; } 我称之为: curl -XPOST “http://localhost:8080/CurlServer/curl/curltutorial/sumPost” -d ‘x:5&y:3’ 问题是System.out.println调用保持零零,似乎我没有正确传递x和y。 更新 在答案之后,我将我的请求更改为: curl -d ‘{“x” : 4, “y”:3}’ “http://localhost:8080/CurlServer/curl/curltutorial/sumPost” -H “Content-Type:application/json” -H “Accept:text/plain” –include […]

Java HttpClient改变内容类型?

我正在为我的Android手机构建一个小应用程序,使用非常基本的REST界面将文本消息转发到Web服务器。 我正在使用android 4.0.3 SDK。 我使用Django和Django restframework包在python中开发了webservice。 设置完全开箱即用。 基本上有一个端点接收包含消息信息(发送者,正文,日期)的JSON对象的POST。 我使用cURL使用以下命令测试了该服务: curl -X POST -H ‘Content-Type: application/json’ –data ‘{“sender”:”+xxxxxxxx”, “body”: “test”, “send_date”:”2011-03-20 16:32:02″}’ http://[…]/messages.json 一切正常,我得到了预期的响应: {“body”: “test”, “send_date”: “2011-03-20T16:32:02”, “id”: 25, “sender”: “+xxxxxxxxxx”} 现在我设置了Android应用程序。 它是一个简单的BroadcastReceiver子类,包含一个私有的AsyncTask类: private class httpPost extends AsyncTask { protected JSONObject doInBackground(String… args) { // Create a new HttpClient and Post Header HttpClient httpclient = […]

使用android volley库发送JSONArray POST请求

我想发送和接收带有齐射的Jsonarrays。 现在我可以收到一个数组,但没关系,但我不知道如何发送请求(例如:使用post方法)。 JsonArrayRequest arrayReq = new JsonArrayRequest(URL, new Listener() { }

Java httpPost成.aspforms

在Java中,如果我想在服务器上发送数据到表单,其中表单类型是: Log in User: Password: Save account 在这种情况下,我必须使用HttpPost方法,因为表单接受方法“post”,因为它在表单定义(初始化)中声明: 在我的例子(Android解决方案)我正在使用 __VIEWSTATE __EVENTTARGET __EVENTARGUMENT ctl00$tbUsername ctl00$tbPwd ctl00$chkRememberLogin ctl00$cmdLogin 值,因为它们是服务器发布post所需的一次。 在没有编程服务器的情况下,我在哪里可以找到服务器所需的内容? 我使用WireShark软件查看客户端和服务器之间的所有响应或传出请求,只需使用httpfilter来查看http事务。 然后使用任何浏览器以通常的方式在线登录,然后在WireShark中,您将看到浏览器和服务器之间的所有请求和响应。 通过已知的IP地址或主机地址找到您感兴趣的那个,然后复制您在任何事务上单击右键时找到的可读字节 。 因此,当您这样做时,您将发现您对服务器的请求必须如何以及需要哪些值。 回到编码(java): public HttpResponse httpPost1(String viewstateValue, String url, String username, String password) throws ConnectTimeoutException { try { // ——–post HttpPost httppost = new HttpPost(url); List nameValuePairs = new ArrayList(); nameValuePairs.add(new BasicNameValuePair(“__VIEWSTATE”, viewstateValue)); nameValuePairs.add(new […]