我正在尝试创建基本身份验证页面,其中我的表单有三个字段
在提交表单时,我只想在JSON格式的HTML上显示来自服务器的返回响应.我对Web服务的AJAX调用还需要设置Authorization标头.但不知何故标题没有设置.我在尝试
beforeSend : function(xhr)
{
xhr.setRequestHeader('Authorization', "Basic ******");
xhr.setRequestHeader("contentType", "application/json;charset=UTF-8");
}
Run Code Online (Sandbox Code Playgroud)
但是当我在控制台中调试代码时,似乎断点永远不会进入这个功能.我是Ajax的新手,并通过在互联网上搜索下面的代码.我在下面发布完整的代码.
码:
$(document).ready(function() {
// process the form
$('form').submit(function(event) {
// get the form data
var formData = {
'username': $('#username').val(),
'password': $('#password').val(),
'grant_type': $('#grantType').val()
};
// process the form
$.ajax({
type : 'POST',
url : 'http://localhost:9090/oauth/token',
beforeSend: function (xhr)
{
xhr.setRequestHeader("Authorization", "Basic ******");
xhr.setRequestHeader("contentType", "application/json;charset=UTF-8");
},
data : formData, // our data object
dataType : 'json', // what type of …Run Code Online (Sandbox Code Playgroud) 我如何从标题绑定对象。我正在使用,[FromHeader(Name = "Custom-Object")]但似乎只能绑定字符串和字符串数组。我需要编写自定义绑定还是在这里缺少什么?我不知道为什么fromheader不能像frombody那样绑定复杂的对象?
c# attributes model-binding request-headers asp.net-core-webapi
我正在编写一个基于Java的Web应用程序,它在实际生产环境中将由另一个应用程序进行前端处理,该应用程序将在请求到达我的应用程序之前设置某些HTTP请求标头.
但是,在开发环境中,我没有前端应用程序,我需要创建一个模拟相同行为的模拟Web应用程序.即这个模拟应用程序应该将请求标头和重定向或转发或任何我不知道的:)设置为我的应用程序中的某个页面.
我怎么能做到这一点?
我遇到此错误消息:
TypeError: add_header() takes exactly 3 arguments (2 given)
使用这些参数时:
testService("SomeServiceName", "POST", "[redacted valid url]", ('Content-type','application/json'), [redacted valid json])
通常这个错误意味着我没有将"self"作为参数传递,但是看到这个方法没有在类中调用,我不知道该怎么做.我已经尝试将self in作为参数传递给参数和方法内部.我已经尝试将标题括在括号和括号中.当我传递"self"时,我收到self未定义的错误消息,当我使用括号而不是括号时,我得到与上面相同的错误.
有魔术Python调试技巧的人吗?非常感谢您抽出宝贵的时间来检查这个!
def testService(name, verb, url, header="", requestBody=""):
#Log out the name of the request we're testing
if (name is not None) or (name.strip() is not ""):
print "Checking " + name + "\n\n"
# Make URL with StoreNumber
if (url is not None) or (url is not ""):
testUrl = url
# If specified verb is GET …Run Code Online (Sandbox Code Playgroud) 不幸的是,虽然可以在生产中设置JavaScript断点,但不能在本地设置它们.在本地,在刷新时,JavaScript执行不受阻碍,就像没有设置断点一样.(已经在Mac OS X上的Chrome,Safari和FF中进行了测试.)
当前本地环境在JavaScript文件的标头中有所不同.
标题粘贴在下方.设置的标头是否有任何不同,这会在本地导致这种不良行为.
谢谢!
General
Remote Address:23.235.33.207:80
Request URL:http://www.example.com/wp-content/themes/example/js/header.top.min.js?ver=1427752599
Request Method:GET
Status Code:200 OK (from cache)
Response Headers
Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Age:149381
Cache-Control:max-age=31536000
Connection:keep-alive
Content-Encoding:gzip
Content-Length:56250
Content-Type:application/javascript
Date:Wed, 01 Apr 2015 15:28:14 GMT
ETag:"2a5ce-5128893ad1780-gzip"
Last-Modified:Mon, 30 Mar 2015 21:58:06 GMT
Server:Apache
Varnish-X-Cache:HIT
Varnish-X-Cache-Hits:4259
Vary:Accept-Encoding
X-Cache:HIT
X-Cache-Hits:4259
X-Served-By:cache-jfk1021-JFK
X-Timer:S1427902094.409391,VS0,VE0
Request Headers
Provisional headers are shown
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36
Query String Parameters
ver:1427752599
Run Code Online (Sandbox Code Playgroud)
General
Remote Address:192.168.33.28:80
Request URL:http://example.local/wp-content/themes/example/js/header.top.min.js?ver=1427902154
Request …Run Code Online (Sandbox Code Playgroud) 也许有人知道为什么 Angular 不理解 HttpParamsOptions,或者也许有另一种方法来添加请求头和参数。
`public getJobs(options: {page?: number, size?: number} = {}, database: string): Observable <IJobs[]> {
const headers = new HttpHeaders().set('Dataset-Id', database);
const params: any = {
page: options.page || 0,
size: options.size || 10
};
const httpParams: HttpParamsOptions = { fromObject: params } as HttpParamsOptions;
const headerwithParams = { params: new HttpParams(httpParams), headers: headers };
return this.http.get<IJobs[]>('/api/jobs', headerwithParams);
}`
Run Code Online (Sandbox Code Playgroud) 昨天我做了一些关于 nodeJS 的演讲。有人问我以下问题:
我们知道 nodeJS 是一个单线程服务器,有几个请求到达服务器,它将所有请求推送到事件循环。如果两个请求同时到达服务器怎么办,服务器将如何处理这种情况?
我猜到了一个想法,回复如下:
我想没有两个 http 请求可以同时到达服务器,所有请求都来自一个套接字,因此它们将在队列中。Http请求格式如下:
请求的时间戳包含在它的标头中,它们可能会根据标头中的时间戳被推送到事件循环。
但我不确定我给了他正确还是错误的答案。
我找不到有关如何使用 Guzzle 6.0 下载远程文件的任何示例。我需要在 GET 请求中传递标头。
我已经查看了根本没有帮助的文档。
我想出了这个,但它仍然没有下载文件
require_once('vendor/autoload.php');
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
$client = new Client();
$response = $client->request('GET', '/stream/20', [
'headers' => [
'Authorization: Token token' => 'df456g4fd564gfs65dg45s6fdg4dsf5g4sd65g',
'Cache-Control' => 'no-cache',
'Content-Type' => 'application/pdf'
],
'sink' => 'https://example.com/path/to/file',
]);
Run Code Online (Sandbox Code Playgroud)
有没有人使用请求头成功下载文件?
尝试为 http 调用设置标头但遇到问题。需要指导Authorization和自定义标题x-api-key。
let url = "http://example.com"
let token = requestToken()
let request = WebRequest.Create(url) :?> HttpWebRequest
request.Method <- "GET"
request.Accept <- "application/json;charset=UTF-8"
request.Headers.Authorization <- sprintf "%s %s" token.token_type token.access_token
request.Headers["x-api-key"] <- "api-key" // custom headers
// or this
request.Headers["Authorization"] <- sprintf "%s %s" token.token_type token.access_token
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
错误 FS3217:此表达式不是函数,无法应用。您是否打算改为访问 indexervia expr.[index] ?
const HEADER_FORWARDED = 0b00001; // When using RFC 7239
const HEADER_X_FORWARDED_FOR = 0b00010;
const HEADER_X_FORWARDED_HOST = 0b00100;
const HEADER_X_FORWARDED_PROTO = 0b01000;
const HEADER_X_FORWARDED_PORT = 0b10000;
const HEADER_X_FORWARDED_ALL = 0b11110; // All "X-Forwarded-*" headers
const HEADER_X_FORWARDED_AWS_ELB = 0b11010; // AWS ELB doesn't send X-Forwarded-Host
Run Code Online (Sandbox Code Playgroud)
我无法理解这一点,为什么他们要这样设置?
request-headers ×10
http ×2
javascript ×2
ajax ×1
angular6 ×1
attributes ×1
breakpoints ×1
c# ×1
download ×1
f# ×1
guzzle6 ×1
http-get ×1
http-headers ×1
java ×1
jquery ×1
node.js ×1
php ×1
python ×1
request ×1
servlets ×1
symfony ×1
tcp ×1
typescript ×1
urllib2 ×1