check POST request with Fiddler - http-post

How can I use Fiddler to check the response from a web server. I could easily check the GET method by pasting the url to the field in Request Builder and get the response back in xml/json. There is an option POST, however I don't know how can I pass the parameters to the POST.
For example:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com/accounts/ClientLogin");
request.Method = "POST";
string postData = "accountType=HOSTED_OR_GOOGLE";
postData += "&Email=yourusername#gmail.com";
postData += "&Passwd=yourpassword";
postData += "&service=finance";
postData += "&source=test-test-.01";
How can I pass my Data into this POST method in Fiddler to get the response?

The simplest way to do this is to have Fiddler capture an instance of this request and drag/drop that session onto the Request builder.
But generating a post yourself isn't hard. Set the RequestBuilder's method to POST, add a header:
Content-Type: application/x-www-form-urlencoded
And put in the Request Body the text of the post:
accountType=HOSTED_OR_GOOGLE&Email=yourusername#gmail.com&Passwd=yourpassword&service=finance&source=test-test-.01

Step 1: Composer with Http Post, URL, Header and Body
Step 2: And Result console.log at Server with Json

Related

How to update api request from postman (form-data) with Laravel update controller?

Postman response
my postman request
Update method controller
I am trying to update the request but return null data from the postman response
$person_ask_per = PersonAskPermission::find($person_ask_per_id);
$person_ask_per->day = $request->day;
$person_ask_per->person_id = $request->person_id;
.....
$person_ask_per->save();
return $person_ask_per
form-data doesn't work for PUT requests in Laravel because Request $request doesn't receive the values. Use the x-www-form-urlencoded instead, it will work. I faced the same problem many times. Just select x-www-form-urlencoded in postman tab.

Http PUT volley. Parameter in the middle of the url

I am using Volley for my HTTP requests and I have an HTTP put URL which looks like below.
http://mycompany.com/favorite/{roomNumber}/count. I am using a JSON object request. How do I make the API work with the extra "/count" in the API? I am passing the parameter room number in the JSON object.
JSON Object request works fine with this type of URL "http://mycompany.com/favorite/{roomNumber}"
JSON Object request
JsonObjectRequest request = new JsonObjectRequest(METHOD_TYPE_PUT, url, jsonObjectParams, responseListener, errorListener)
Can somebody help me with passing the JSON object parameter in the middle of the URL
Thanks.
You can call the API dynamically like this,
private void getTheApiData(int roomNumber){
JsonObjectRequest request = new JsonObjectRequest(METHOD_TYPE_PUT,
"mycompany.com/favorite" + roomNumber + "/count",
jsonObjectParams, responseListener, errorListener)
}
and call the above API dynamically by the method when you get the new data every time like this.
getTheAPiData(20) //if room number is 20
let me know if you have any issue #Shravani

Django testing - test the view which handles an ajax call

In testing Django, the view is returning 200 code but not sending any error message related.
def ajax_view(request):
msg = ''
if request.is_ajax():
username = request.POST['username']
user = User.objects.get(username=username)
msg = 'user exists'
return HttpResponse(msg)
In tests.py
response = self.client.post(reverse('ajax_view'), data={'username': 'hello'})
self.assertEqual(200, response.status_code)
self.assertContains(response, 'exist')
It seems it is not going through the request.is_ajax().. How can I mock the ajax call in Django testing?
The docs on the test client mention this; you need to pass the HTTP_X_REQUESTED_WITH header, which you can do as a keyword argument.
Also, if you pass content_type as 'application/json', Django will automatically serialize to JSON. So:
response = self.client.post(
reverse('ajax_view'),
data={'username': 'hello'},
content_type='application/json',
HTTP_X_REQUESTED_WITH='XMLHttpRequest'
)
Not entirely sure this will resolve the entire issue but your method may be expecting the data in a json format:
json_data = json.dumps({'username': 'hello'})
response = self.client.post(reverse('ajax_view'), data=json_data)

Spring receiving empty body

I'm using Spring for my backend. I have the following code:
#RequestMapping(value = "/test", method = RequestMethod.POST)
#CrossOrigin
public void test(HttpServletRequest request) {
System.out.println(request.getParameterMap().size());
System.out.println(new JSONObject(request.getParameterMap()));
}
When I send JSON data using Postman, I get a map of all the parameters I've sent.
But when I'm making the same call from my website, I get an empty map with size 0. I do not get any error or exception on both front and back sides.
What could be the reason?
Thank you
Most probably getParameterMap() is really empty in your case, because parameters are not passed as query, but as a body (content) of HTTP request when it is sent from your web-site.
It can also be affected by the Content-Type and Accept headers of the HTTP request.
According to official documentation ServletRequest.getParameterMap() returns:
For HTTP servlets, parameters are contained in the query string or posted form data.
Usually "posted form data" implies: HTTP header Content-Type: application/x-www-form-urlencoded and URL encoded name-value pairs of parameters in the content of HTTP request.
If your web-site sends application/json, any other content type, or does not define content type at all, it might not be properly mapped into the request parameters by servlet container. In this case you should look into the body of HTTP request (ServletRequest.getReader()) to get the payload, or let Spring MVC do that (e.g. #RequestBody annotation).

Angular 2 HTTP post to Web API without [FromBody]

I have a sample Angular 2 code below.
this.headers = new Headers({ 'Content-Type': 'application/json' });
this.options = new RequestOptions({ headers: this.headers });
this.http.post('/api/todo/create', JSON.stringify(todo), this.options);
I also have an API action as seen below (ASP.NET Core)
[HttpPost]
[Route("create")]
public IActionResult Create([FromBody] Todo todo)
{
return this.Ok();
}
This code works but I am not comfortable in seeing the [FromBody] attribute in the parameter. I know that for Post requests, MVC reads it from the body. But, I have been using Restangular in AngularJS before and the parameter object is sent to an API without the [FromBody] attribute.
Is there a way to just pass the object to the API action without using the [FromBody] attribute or reading the content of the request and then deserializing it to an object?
I think using the payload of a POST method is what you should do to send data to the server. You can choose the content type you want (JSON, url encoded form, ...).
That said, the Angular2 HTTP support is low-level. I mean there is no high-level API for REST. You need to set headers by your own, choose the HTTP method you want to use... I won't find something like Restangular in Angular2.
This link could help you:
https://www.quora.com/What-are-some-of-the-best-practices-for-designing-a-RESTful-API

Resources