菜鸟教程小白 发表于 2022-12-11 20:27:25

iphone - API key 必须作为 API-Key header 在每个请求中传递


                                            <p><p>我想在每个请求的 header 中传递 API-Key。</p>

<pre><code> NSMutableURLRequest* request = [ initWithURL:];
NSLog(@&#34;%@&#34;,request );
;

;

request = cachePolicy:
         NSURLRequestUseProtocolCachePolicy timeoutInterval:100];

NSLog(@&#34;%@&#34;,url);
NSLog(@&#34;%@&#34;,);
</code></pre>

<p>allHTTPHeaderFields 为空。我错过了什么吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您首先使用具有 header 字段的 <code>NSMutableURLRequest</code> 初始化请求,然后使用在 header 字段中没有 APIkey 的 <code>NSURLRequest</code> 覆盖它。
只需摆脱这一行:</p>

<pre><code>request = cachePolicy:
         NSURLRequestUseProtocolCachePolicy timeoutInterval:100];
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - APIkey 必须作为 API-Keyheader 在每个请求中传递,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8020179/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8020179/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - API key 必须作为 API-Key header 在每个请求中传递