http-post

Using HttpClient and HttpPost in Android with post parameters

情到浓时终转凉″ 提交于 2019-11-27 00:32:11
I'm writing code for an Android application that is supposed to take data, package it as Json and post it to a web server, that in turn is supposed to respond with json. Using a GET request works fine, but for some reason using POST all data seems to get stripped and the server does not receive anything. Here's a snippet of the code: HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 5000); HttpConnectionParams.setSoTimeout(params, 5000); DefaultHttpClient httpClient = new DefaultHttpClient(params); BasicCookieStore cookieStore = new BasicCookieStore()

Posting JSON data using AFNetworking 2.0

此生再无相见时 提交于 2019-11-27 00:14:07
I have a web script which accepts JSON string as input through HTTP POST request. I have came across several AFNetworking 1.x example for the same , can anybody please point me or give AFNetworking 2.0 example to do an HTTP POST request to a web script with formatted JSON as input ? Thanks after searching docs and trying out some codes I got following as an example AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; NSDictionary *params = @ {@"user" :txtUserName, @"pwd" :txtPwd }; [manager POST:URL

Spring MVC - Why not able to use @RequestBody and @RequestParam together

☆樱花仙子☆ 提交于 2019-11-26 23:59:15
Using HTTP dev client with Post request and Content-Type application/x-www-form-urlencoded 1) Only @RequestBody Request - localhost:8080/SpringMVC/welcome In Body - name=abc Code- @RequestMapping(method = RequestMethod.POST) public String printWelcome(@RequestBody String body, Model model) { model.addAttribute("message", body); return "hello"; } // Gives body as 'name=abc' as expected 2) Only @RequestParam Request - localhost:8080/SpringMVC/welcome In Body - name=abc Code- @RequestMapping(method = RequestMethod.POST) public String printWelcome(@RequestParam String name, Model model) { model

Access POST values in Symfony2 request object

萝らか妹 提交于 2019-11-26 23:49:31
OK, this is a newbie question, but I can't find the answer anywhere. In a controller in Symfony2, I want to access the POST value from one of my forms. In the controller I have: public function indexAction() { $request = $this->get('request'); if ($request->getMethod() == 'POST') { $form = $this->get('form.factory')->create(new ContactType()); $form->bindRequest($request); if ($form->isValid()) { $name_value = $request->request->get('name'); Unfortunately $name_value isn't returning anything. What am I doing wrong? Thanks! Symfony 2.2 this solution is deprecated since 2.3 and will be removed

Send POST Request with Data Specified in File via Curl

戏子无情 提交于 2019-11-26 23:41:53
I need to make a POST request via Curl from the command line. Data for this request is located in a file. I know that via PUT this could be done with the --upload-file option. curl host:port/post-file -H "Content-Type: text/xml" --data "contents_of_file" Richard J You're looking for the --data-binary argument: curl -i -X POST host:port/post-file \ -H "Content-Type: text/xml" \ --data-binary "@path/to/file" In the example above, -i prints out all the headers so that you can see what's going on, and -X POST makes it explicit that this is a post. Both of these can be safely omitted without

Target host must not be null, or set in parameters

徘徊边缘 提交于 2019-11-26 23:34:44
问题 I get this error "Target host must not be null, or set in parameters". My manifest file has internet permission set, and I have put 'http://' before my Url. It still gives the same error. My URL does not have a 'www.' attached to it. Part of my Code: HttpPost post = new HttpPost("http://infocreation.something_something1.xml"); Part of my manifest is like below: <uses-permission android:name="android.permission.INTERNET/> What do I do now? 回答1: It should be HttpPost post = new HttpPost("http:/

HTTP POST Returns Error: 417 “Expectation Failed.”

☆樱花仙子☆ 提交于 2019-11-26 23:29:51
When I try to POST to a URL it results in the following exception: The remote server returned an error: (417) Expectation Failed. Here's a sample code: var client = new WebClient(); var postData = new NameValueCollection(); postData.Add("postParamName", "postParamValue"); byte[] responseBytes = client.UploadValues("http://...", postData); string response = Encoding.UTF8.GetString(responseBytes); // (417) Expectation Failed. Using an HttpWebRequest/HttpWebResponse pair or an HttpClient doesn't make a difference. What's causing this exception? System.Net.HttpWebRequest adds the header 'HTTP

Http Post for Windows Phone 8

人盡茶涼 提交于 2019-11-26 22:54:27
I am new to C# so I was wondering if someone can help me out on this. I am trying to send HttpPost from Windows Phone 8 to the server. I found two examples that I would like to combine. The first one is an example of sending Http Post ( http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetrequeststream.aspx ). The problem with this one is that it is not support by Windows Phone 8. The second example is using the BeginGetResponse ( http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.net.httpwebrequest(v=vs.105).aspx ). This supports windows phone 8. I need

Go HTTP Post and use Cookies

痴心易碎 提交于 2019-11-26 22:45:55
问题 I'm trying to use Go to log into a website and store the cookies for later use. Could you give example code for posting a form, storing the cookies, and accessing another page using the cookies? I think I might need to make a Client to store the cookies, by studying http://gotour.golang.org/src/pkg/net/http/client.go package main import ("net/http" "log" "net/url" ) func Login(user, password string) string { postUrl := "http://www.pge.com/eum/login" // Set up Login values := make(url.Values)

how to post plain text to ASP.NET Web API endpoint?

旧时模样 提交于 2019-11-26 22:45:05
问题 I have an ASP.NET Web API endpoint with controller action defined as follows : [HttpPost] public HttpResponseMessage Post([FromBody] object text) If my post request body contains plain text ( i.e. should not be interpreted as json, xml, or any other special format ), then I thought I could just include following header to my request : Content-Type: text/plain However, I receive error : No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'text