I am using to get the targeturl using
httpSessionRequestCache.getRequest(request, response).getRedirectUrl();
it's only returning localhost:8080 because of this the redirection is not happening
I am expecting this should return as
http://localhost:8080
Any suggestions?
Related
I have created some curl command to send a POST to my server where I am listening on that port for input to trigger additional action. The command is the following (Just masked the URL):
curl -v -H "Content-Type: application/json" -X POST -d "{\"Location\":\"Some Name\",\"Value\":\"40%\"}" http://example.com:8885/
I get the following output from curl:
About to connect() to example.com port 8885 (#0)
Trying 5.147.XXX.XXX...
Connected to example.com (5.147.XXX.XXX) port 8885 (#0)
POST / HTTP/1.1
User-Agent: curl/7.29.0
Host: example.com:8885
Accept: /
Content-Type: application/json
Content-Length: 40
upload completely sent off: 40 out of 40 bytes
However after that curl does not close the connection. Am I doing something wrong? Also on the server I only receive the POST as soon as I hit ctrl+c.
It sits there waiting for the proper HTTP response, and after that has been received it will exit cleanly.
A minimal HTTP/1.1 response could look something like:
HTTP/1.1 200 OK
Content-Length: 0
... and it needs an extra CRLF after the last header to signal the end of headers.
I'm a bit rusty on this, but according to section 6.1 of RFC7230, you might need to add a Connection: close header as well. Quoting part of the paragraph:
The "close" connection option is defined for a sender to signal
that this connection will be closed after completion of the
response. For example,
Connection: close
in either the request or the response header fields indicates that
the sender is going to close the connection after the current
request/response is complete (Section 6.6).
Let me know if it solves your issue :-)
Is there a question mark in link ?
I found that my link had question mark like http... .com/something/something?properties=1 and i tried header connection: close but it was still active so i tried then removing ?properties etc. and it worked...
I'm following Spotify's client credentials authorization flow, but all of my curl requests are returning {"error":"invalid_client"} each time. Here are the instructions from Spotify:
The request will include parameters in the request body:
grant_type - Set to “client_credentials”.
The header of this POST request must contain the following parameter:
Authorization - A Base 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization: Basic <base64 encoded client_id:client_secret>
They also include an example of a curl request:
$ curl -H "Authorization: Basic ZjM4ZjAw...WY0MzE=" -d grant_type=client_credentials https://accounts.spotify.com/api/token
Following their example, so far I've tried curl requests with:
client_id and client_secret plain
both base64 encoded seperately
only one or the other encoded
both encoded as one string with the colon
both encoded as one string without the colon
each of the above with a regenerated client secret
I'm using Ruby's Base64#encode64 method to encode. Still no luck. Any helpful hints?
Okay, I got it working - passing my client_id and client_secret, separated by a colon, to Base64.strict_encode64 (NOT Base64.encode64) and then passing that to the above curl request gets a 200 response with an access token. Apparently encode64 was not enough.
I ran into this error when I ran the curl command in my terminal.
-bash: unexpected EOF while looking for matching `"'
Solved by using single quotes instead of double quotes.
I'm testing malformed HTTP requests on OSX, but I can't workout how to make a request with a missing/malformed http version.
Curl seems to only allow valid presets (--http1.0, --http1.1, --http1)
Whats the easiest way to construct a request without "http version"?
Example:
Given the following commands create the following request lines:
Ex1.
command: curl -i http://localhost:8080/cat.jpg?v=1
request: GET cat.jpg?v=1 HTTP/1.1
Ex2.
command: curl -i http://localhost:8080/cat.jpg?v=1 --http1.0
request: GET cat.jpg?v=1 HTTP/1.0
Wanted
How could I create the following
command: ???
request: GET cat.jpg?v=1 (missing http version)
EDIT: ANSWER
curl only deals with valid requests. netcat is an alternative that has more control.
See this answer
Thanks #DanFromGermany
I am writing a simple server in Ruby in order to understand the Socket module. Here is my code:
require 'socket'
s = TCPServer.new(3939)
loop do
c = s.accept
STDERR.puts c.gets
c.close
end
I simply want to print the request to the server console before closing the socket. Why does it print the request thrice, instead of just once?
If I curl that code
$ curl localhost:3939
I get an empty reply
curl: (52) Empty reply from server
and a single GET request
GET / HTTP/1.1
I'm very new to Go. Tried this first hello, world from the documentation, and wanted to read the Host and Scheme from the request:
package hello
import (
"fmt"
"http"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Host: " + r.URL.Host + " Scheme: " + r.URL.Scheme)
}
But their values are both blank. Why?
Basically, since you're accessing the HTTP server not from an HTTP proxy, a browser can issue a relative HTTP request, like so:
GET / HTTP/1.1
Host: localhost:8080
(Given that, of course, the server is listening on localhost port 8080).
Now, if you were accessing said server using a proxy, the proxy may use an absolute URL:
GET http://localhost:8080/ HTTP/1.1
Host: localhost:8080
In both cases, what you get from Go's http.Request.URL is the raw URL (as parsed by the library). In the case you're getting, you're accessing the URL from a relative path, hence the lack of a Host or Scheme in the URL object.
If you do want to get the HTTP host, you may want to access the Host attribute of the http.Request struct. See http://golang.org/pkg/http/#Request
You can validate that by using netcat and an appropriately formatted HTTP request (you can copy the above blocks, make sure there's a trailing blank line after in your file). To try it out:
cat my-http-request-file | nc localhost 8080
Additionally, you could check in the server/handler whether you get a relative or absolute URL in the request by calling the IsAbs() method:
isAbsoluteURL := r.URL.IsAbs()