http-headers

How to get a null value if the header doesn't exist

和自甴很熟 提交于 2019-12-13 13:34:20
问题 I am using the request context to get the value of the header called "token". var token = context.request.Headers.GetValues("Token") Now If the header exists. This all works hundreds, But now if the header doesn't exist, I want it to return null. But instead it throws an exception System.InvalidOperationExecption Is my only option to throw a try catch around it? 回答1: you can do this if (Context.Request.Headers["Token"] != null) { var token = Context.Request.Headers.GetValues("Token"); return

Getting Header Response in Swift

倖福魔咒の 提交于 2019-12-13 11:42:26
问题 I am following this answer for making HTTP calls in my swift project. How to make an HTTP request in Swift? and following is the code I am using to make a synchronous call let urlPath: String = "http://apiserver.com/api/login/?username=asdf&password=asdf" var url: NSURL = NSURL(string: urlPath)! var request1: NSURLRequest = NSURLRequest(URL: url) var response: AutoreleasingUnsafeMutablePointer<NSURLResponse?> = nil var error: NSErrorPointer = nil var dataVal: NSData = NSURLConnection

How to pass authorization token header objective c?

≯℡__Kan透↙ 提交于 2019-12-13 08:46:58
问题 I'm passing username,password for an API call it returns right value. But after authentication API returns an security token I need to capture the token and pass along with username and password.I'm doing the same but it returns forbidden error which denotes invalid token error.I also tried base64 to pass token as suggested at some answer in stackoverflow.The code I use to pass header values below NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:

understanding http request format

我的梦境 提交于 2019-12-13 08:46:48
问题 Following are 3 http header request format i have extracted from google chrome browser. Those 3 request format are for html, xml and json. How the server will know which one is html, xml or json and respond accordingly? Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Connection:keep-alive Cookie:_depot_session

Why the header function is not working after CURL call?

自古美人都是妖i 提交于 2019-12-13 08:09:02
问题 Following is the call to an URL using CURL : <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); $link = $_GET['link']; $url = "http://www.complexknot.com/user/verify/link_".$link."/"; // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources

CORS with reverse proxy Nginx server and nodejs won't work

主宰稳场 提交于 2019-12-13 08:05:19
问题 I am working on a server with nodejs the server is running on a VPS I hire. From the localhost on my pc, I send a request to the server but all it gives me back is: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8086' is therefore not allowed access. But I have this in my default file in de Nginx configuration: location / { proxy_set_header 'Access-Control-Allow-Origin' '*'; proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST,

Setting headers on redirected external URL

三世轮回 提交于 2019-12-13 07:35:42
问题 Is it possible that a jsf application can navigate to an external link and specify headers for that external link? So far I have tried to call in the backing bean method: ExternalContext#setResponseHeader(java.lang.String name, java.lang.String value) ExternalContext#redirect(java.lang.String url) The redicection is successfully executed but the Headers are lost. Is there any way to specify a link accompanied with the headers? 回答1: No, HTTP doesn't allow setting headers on a different request

Custom headers per request in RestKit

╄→гoц情女王★ 提交于 2019-12-13 06:26:08
问题 I am trying to submit a request to the server,using RestKit 0.20.3 which needs different headers depending on some state of the application i read these posts : question1 question2 and they don't help, because this api is not available how do i add custom headers to RestKit's url requests ? 回答1: Question 2 is the correct technique, you just need to use the new API: request = [objectManager requestWithObject: method: path: parameters:]; Then create the operation: operation = [objectManager

How to determine the right Accept Content-Type with ExpressJS

╄→гoц情女王★ 提交于 2019-12-13 06:25:05
问题 I'm having trouble to distinguish an ajax call from other calls in ExpressJS. As far as I understand, I can use request.accepts('json') to identify a json request? The problem is - apparently, every call accepts everything! app.get( '*', function(request, response, next ) { console.log('request accepts:') if( request.accepts( 'json' ) ){ console.log( '--> accepts json' ) } if( request.accepts( 'html' ) ){ console.log( '--> accepts html' ) } if( request.accepts( 'blah' ) ){ console.log( '-->

return dynamic image zf2

血红的双手。 提交于 2019-12-13 06:20:21
问题 I use zend framework 2 and try to return an created with gd2 library jpeg image . but it doesn't work. could you look my code what's the problem? My code is run with plain php in normally but in zf2 problem? class PictureController extends AbstractActionController { public function colorPaletteAction(){ .... .... //canvas created at above. imagejpeg($canvas); imagedestroy($canvas); $response = $this->getResponse(); return $response->getHeaders()->addHeaderLine('Content-Type', 'image/jpeg'); }