http-post

Reading FromUri and FromBody at the same time

送分小仙女□ 提交于 2019-11-26 09:48:18
问题 I have a new method in web api [HttpPost] public ApiResponse PushMessage( [FromUri] string x, [FromUri] string y, [FromBody] Request Request) where request class is like public class Request { public string Message { get; set; } public bool TestingMode { get; set; } } I\'m making a query to localhost/Pusher/PushMessage?x=foo&y=bar with PostBody: { Message: \"foobar\" , TestingMode:true } Am i missing something? 回答1: A post body is typically a URI string like this: Message=foobar&TestingMode

.NET: Simplest way to send POST with data and read response

拜拜、爱过 提交于 2019-11-26 09:39:44
To my surprise, I can't do anything nearly as simple as this, from what I can tell, in the .NET BCL: byte[] response = Http.Post ( url: "http://dork.com/service", contentType: "application/x-www-form-urlencoded", contentLength: 32, content: "home=Cosby&favorite+flavor=flies" ); This hypothetical code above makes an HTTP POST, with data, and returns the response from a Post method on a static class Http . Since we're left without something this easy, what's the next best solution? How do I send an HTTP POST with data AND get the response's content? Chris Hutchinson using (WebClient client = new

Using HttpClient and HttpPost in Android with post parameters

寵の児 提交于 2019-11-26 09:27:08
问题 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);

jQuery Ajax POSTing array to ASP.NET MVC Controller

☆樱花仙子☆ 提交于 2019-11-26 09:24:29
问题 I\'m missing something here. I\'ve got this jQuery JavaScript: $.ajax({ type: \"POST\", url: \"/update-note-order\", dataType: \"json\", data: { orderedIds: orderedIds, unixTimeMs: new Date().getTime() } }); Where orderedIds is a JavaScript number array (e.g. var orderedIds = [1, 2] ). The handling Controller method is: [HttpPost] public void UpdateNoteOrder(long[] orderedIds, long unixTimeMs) { ... } When I put a Debugger.Break() in UpdateNoteOrder() , orderedIds is null in the Watch window.

How to prevent submitting the HTML form's input field value if it empty

风格不统一 提交于 2019-11-26 09:02:07
问题 I have HTML form with input fields. Some of inputs can be empty, i.e. the value is \"\". <input name=\"commentary\" value=\"\"> Just now, when commentary field is not set, it appears in submit url like: &commentary= How I can remove empty inputs from the submit url, so when the commentary input is empty it would not be passed at all. Thank you very much. Update Thanks to minitech answer, I could resolve it. JavaScript code is below: $(\'#my-form-id\').submit(function() { var commentary = $(\'

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

六眼飞鱼酱① 提交于 2019-11-26 08:49:27
问题 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-

Access POST values in Symfony2 request object

一笑奈何 提交于 2019-11-26 08:49:08
问题 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

Http Post for Windows Phone 8

∥☆過路亽.° 提交于 2019-11-26 08:28:17
问题 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

How to receive json data using HTTP POST request in Django 1.6?

本秂侑毒 提交于 2019-11-26 08:00:01
问题 I am learning Django 1.6. I want to post some JSON using HTTP POST request and I am using Django for this task for learning. I tried to use request.POST[\'data\'] , request.raw_post_data , request.body but none are working for me. my views.py is import json from django.http import StreamingHttpResponse def main_page(request): if request.method==\'POST\': received_json_data=json.loads(request.POST[\'data\']) #received_json_data=json.loads(request.body) return StreamingHttpResponse(\'it was

How to set a Header field on POST a form?

不想你离开。 提交于 2019-11-26 07:36:05
问题 How can I set a custom field in POST header on submit a form? 回答1: It cannot be done - AFAIK. However you may use for example jquery (although you can do it with plain javascript) to serialize the form and send (using AJAX) while adding your custom header. Look at the jquery serialize which changes an HTML FORM into form-url-encoded values ready for POST. UPDATE My suggestion is to include either a hidden form element a query string parameter 回答2: Set a cookie value on the page, and then read