How to print out http-response header in Python

Update: Based on comment of OP, that only the response headers are needed. Even more easy as written in below documentation of Requests module: We can view the server’s response headers using a Python dictionary: >>> r.headers { ‘content-encoding’: ‘gzip’, ‘transfer-encoding’: ‘chunked’, ‘connection’: ‘close’, ‘server’: ‘nginx/1.0.4’, ‘x-runtime’: ‘148ms’, ‘etag’: ‘”e1ca502697e5c9317743dc078f67693f”‘, ‘content-type’: ‘application/json’ } And especially … Read more

RSpec testing redirect to URL with GET params

From the documentation, the expected redirect path can match a regex: expect(response).to redirect_to %r(\Ahttp://example.com) To verify the redirect location’s query string seems a little bit more convoluted. You have access to the response’s location, so you should be able to do this: response.location # => http://example.com?foo=1&bar=2&baz=3 You should be able to extract the querystring params … Read more

RestTemplate – Handling response headers/body in Exceptions (RestClientException, HttpStatusCodeException)

I finally did it using ResponseErrorHandler. public class CustomResponseErrorHandler implements ResponseErrorHandler { private static ILogger logger = Logger.getLogger(CustomResponseErrorHandler.class); private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler(); public void handleError(ClientHttpResponse response) throws IOException { List<String> customHeader = response.getHeaders().get(“x-app-err-id”); String svcErrorMessageID = “”; if (customHeader != null) { svcErrorMessageID = customHeader.get(0); } try { errorHandler.handleError(response); } catch (RestClientException scx) … Read more

Create HTTP post request and receive response using C# console application

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; namespace WebserverInteractionClassLibrary { public class RequestManager { public string LastResponse { protected set; get; } CookieContainer cookies = new CookieContainer(); internal string GetCookieValue(Uri SiteUri,string name) { Cookie cookie = cookies.GetCookies(SiteUri)[name]; return (cookie == null) ? null : cookie.Value; } public string GetResponseContent(HttpWebResponse response) … Read more

Symfony redirect to external URL

Answer to your question is in official Symfony book. http://symfony.com/doc/current/book/controller.html#redirecting public function indexAction() { return $this->redirect(‘http://stackoverflow.com’); // return $this->redirect(‘http://stackoverflow.com’, 301); – for changing HTTP status code from 302 Found to 301 Moved Permanently } What is the “URL”? Do you have really defined route for this pattern? If not, then not found error is absolutelly … Read more

Create http.Response instance with sample body string in golang

As suggested by Not_a_Golfer and JimB: io.ReadCloser is an interface that is satisfied when a struct implements both the Read and the Close functions. Fortunately, there is io.NopCloser, which takes a io.Reader and wraps it in the nopCloser struct, which implements both Read and Close. However, its Close function does nothing as implied from the … Read more