Syntax for POST request - http

I am trying to make a POST request to the following url: http://xxx.xxx.xxx.xxx/api/signup
However I get this response:
http://xxx.xxx.xxx.xxx/api/signup?first_name=&last_name=&email_id=&password=&dob ...Please pass parameters...
So I tried making the request like this:
http://xxx.xxx.xxx.xxx/api/signup?first_name=Jay&last_name=Last&email_id=Jay#test.com&password=qqq&dob=1/1/15
But I get the same response.
I have no idea what the correct syntax is supposed to be...
Can someone please explain how I should rewrite the url?
Edit
After I make the request, if successful, I get a response saying "success new user" and a JSON with the key/vals

Does encoding your values make any difference?
for example:
http://xxx.xxx.xxx.xxx/api/signup?first_name=Jay&last_name=Last&email_id=Jay%40test.com&password=qqq&dob=1%2F1%2F15

Related

Wrong result using POST method

Can't seem to get the right result using POST method.
I'm trying to access the "MATRICULE" page on this website https://servicesenligne2.ville.montreal.qc.ca/sel/evalweb/index
This is what the response looks like :
However, I always end up on the "SEARCH BY ADDRESS" page. Here's the result I get with POSTMAN.
Any ideas why this might happen ?
You forgot to enable key-value of form-data

Tracing an HTTP request in Go in a one structured log line

I have learned you can "decorate" the HTTP transport so that you can details of the request, however I can't quite figure out how you log the URL in the same line.
https://play.golang.org/p/g-ypQN9ceGa
results in
INFO[0000] Client request dns_start_ms=0 first_byte_ms=590 response_code=200 total_ms=590 url=
INFO[0000] 200
I'm perpetually confused if I should be using https://golang.org/pkg/context/#WithValue to pass around the context in a struct, especially in light where https://blog.golang.org/context-and-structs concludes with pass context.Context in as an argument.
Go through the behaviour of how the request is constructed in request.go from net/http. You see that the RequestURI field is never set there. Quoting from same reference,
Usually the URL field should be used instead.
It is an error to set this field in an HTTP client request
So, I would suggest you to use request.URL instead.
It is a parsed from the request uri. It should have the data you need.
You can construct the output as following:
f := log.Fields{
"url": fmt.Sprintf("%s %s%s", r.Method, r.URL.Host, r.URL.Path),
}
Also, in my experience, it is far more easier to use context.WithValue and pass the context as an argument.
Replace r.RequestURI by r.URL.String() in your code to log the full, valid URL (https://golang.org/pkg/net/url/#URL.String). RequestURI is empty on the client side (https://golang.org/pkg/net/http/#Request), as the output from your code is showing.
I don't see how context.Context relates to your question, but I believe https://blog.golang.org/context-and-structs is considered "best practice".

Symfony 4 - Send POST request with multipart/form-data

I want to send a POST request to register my users, but I don't want to type my login and password in the URL, like this. I wanted to use the multipart/form-data format, to send my arguments as if they were in a form, like that.
Do you know how can I do that?
Thanks in advance! ^^
If you want to make a POST request to some URL with some data, I suggest encoding the data in json format.
See json_encode or Symfony serializer or jms_serializer.
Or, if you wish, you can send url encoded data, using http_build_query.
Just remember to send the right Content-type header, application/json or application/x-www-form-urlencoded.
And to perform the request, consider using Guzzle or cURL.
I realize I've just provided you with official docummmentation about related stuff, but I haven't fully understood your question, so I tried giving you general pointers for you to research. There are good examples of certain functionallities I believe you will need in order to do this.
Assuming you have the URL to make the request:
gather the data to post
serialize the gathered data
execute the request to the url with the serialized data
parse the response body
continue doing your logic
In case this isn't what you were looking for, please provide some more context, some code you have (don't share any sensitive data), or something, so you could get more precise answers. I hope I've managed to help. Feel free to ask more questions.
Okay I used $request->request->get() to extract my values , like this :
$entityManager = $this->getDoctrine()->getManager();
$user = new User();
$user->setLogin($request->request->get('login'));
$user->setPassword($request->request->get('password'));
$entityManager->persist($user);
$entityManager->flush();
And then I serialize my values in a JSON object, it's working perfectly ^^ Thanks for your help! ^^

JSON API response for a collection POST that couldn't be performed

I am building an API where one can issue a POST to /users/1/suggestions/make in order to get a new suggestion. There are two cases:
the server can create a suggestion based on POSTed params, in which case a 200 status code is returned together with the created suggestion;
the server cannot create a suggestion based on POSTed params, in which case I am not sure what status code to return (200, since the request succeeded but nothing could be suggested, 404 because a suggestion could not be computed, or something else) and what content (nil, an empty response, something else).
If your POST is unsuccessful due to the parameters not passing validation, it is appropriate to return HTTP 400 Bad Request. The response body should consist of a list of the errors that caused the rejection.
This way it is clear to the API caller that no data has been modified.

Bad Request (400): Why?

Why do I get a 400 - bad request error using the following URL? It is encoded using Server.UrlEncode. The actual path query parameter is C:\Development\Chase\Exports\ChaseExport-090312073930.zip
http://localhost:50199/Common/Forms/Export_Stream.aspx%3fpath%3dC%3a%5CDevelopment%5CChase%5CExports%5CChaseExport-090312073930.zip
You should not urlencode the entire querystring, just the values, so URL should be
http://localhost:50199/Common/Forms/Export_Stream.aspx?path=C%3a%5CDevelopment%5CChase%5CExports%5CChaseExport-090312073930.zip
I've written an article with Stefan's help that explains how to do this:
Experiments in Wackiness: Allowing percents, angle-brackets, and other naughty things in the ASP.NET/IIS Request URL
Try this:
http://localhost:50199/Common/Forms/Export_Stream.aspx?path=C%3a%5CDevelopment%5CChase%5CExports%5CChaseExport-090312073930.zip

Resources