我倾向于http标头,我想在"缓存控制"字段上运行测试,所以我构建了一个只有一个默认页面的asp.net网站.在这个页面我正在测试"缓存控制" "下面的Page_Load中包含代码的字段:
Response.AddHeader("Cache-Control","max-age=3600");
Response.Write(new Random().Next(0,9999).ToString());
Run Code Online (Sandbox Code Playgroud)
每当我刷新页面时,我认为它会给我相同的数字,因为当它收到"Cache-Control:max-age = 3600"标题时,页面被浏览器缓存在本地,但令我惊讶的是,它给了我每次按下刷新按钮(不是ctrl + f5)时都会有一个新的数字,就像缓存控件根本不起作用一样.
我使用fiddler捕获请求/响应信息,并且在请求头中看到"Cache-Control:max-age = 0",而响应头中的"Cache-Control:max-age = 3600".似乎"Cache-Control:max-age = 0"会阻止缓存,但为什么呢?我错过了什么吗?
我想知道如何实现303重定向显示post数据.
例:
I send the form.
Redirect
Page displays the info I just posted. (Eg: Name, email).
Run Code Online (Sandbox Code Playgroud)
我认为它是用参数完成的,/index.php?name=TheName&email=theEmail但我不确定,因为我试图找到一些好的文章解释它但不能.
非常感谢.
我试图将一些自定义标头参数添加到HTTP 303(重定向)响应.但是,新标题似乎从响应中被剥离.
此代码用于接收请求并返回HTTP 303响应:
@POST
@Path("/authorize")
@Produces("application/x-www-form-urlencoded")
public Response getOAuthGrant(@HeaderParam(OAuth2.AUTHORIZATION) @DefaultValue("") String authorization,
@HeaderParam(OAuth2.CLIENT_ID) @DefaultValue("") String clientId,
@HeaderParam(OAuth2.CLIENT_SECRET) @DefaultValue("") String clientSecret,
@HeaderParam(OAuth2.GRANT_TYPE) @DefaultValue("") String grantType) throws InternalServerException, UnauthorizedException {
OAuth2.validateGrantRequest(clientId, clientSecret, authorization, grantType);
ApiTokenV2 apiTokenV2 = new ApiTokenV2();
try {
apiTokenV2 = TokenManager.getApiToken(clientId);
if (apiTokenV2 != null) {
apiTokenV2.generateAccessGrant(clientId);
} else {
logger.error("Error in TokenEndpoint. Retrieved token is null.");
throw new InternalServerException("A server error occurred while trying to authorize the requester. Could not find 'generateAccessGrant' method");
}
} catch (NamingException …Run Code Online (Sandbox Code Playgroud) 我有一个带有上传字段的ExtJs表单.当我对表单进行求和时,Accept-header是错误的.响应是JSON,但发送的Accept-header是:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Run Code Online (Sandbox Code Playgroud)
我有根据的猜测是它是浏览器的默认值.
在Chrome中,会出现警告:资源被解释为Document但是使用MIME类型application/json进行传输.
在FireFox中,这会导致文件下载.
结论:我必须将Accept-header更改/设置为 application/json
Sencha的文档 sais它有一个headers参数,但我已经测试过,对于fileupload它不起作用.评论称它不受支持.(在另一个线程中找到相同的结果)
任何摆脱文件下载/设置正确的Accept-header的建议......它不一定是ExtJs sollution.如果你能给我一个简单的javaScript解决方案来设置文件上传表单上的accept头,我可以把它塑造成一个sencha框架.
更新:
ExtJS表单提交:
form.submit({
url: API_URLS.addDocument,
waitMsg: 'Uploading your document...',
headers: {
"Accept": 'application/json' //doesn't work
},
success: function() {
...
},
failure: function(){
...
}
});
Run Code Online (Sandbox Code Playgroud)
在幕后它创建了一个类似于此的普通形式:
<form action="API_URLS.addDocument" enctype="multipart/form-data" method="post">
<input type="file"/>
</form>
Run Code Online (Sandbox Code Playgroud)
哪个可以通过javaScript(submit())提交
有没有办法从LWP的HTTP请求中获取原始的,未修改的响应头?这适用于需要识别可能格式错误的标头问题的诊断工具.
我发现最接近的是:
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $response = $ua->get("http://somedomain.com");
print $response->headers()->as_string();
Run Code Online (Sandbox Code Playgroud)
但这实际上解析了标题,然后从解析的数据中重构了它们的规范化,清理后的版本.我真的需要完整的服务器返回形式的整个标题文本,因此任何格式错误或非标准的标题都将清晰可辨.
如果事实证明LWP无法做到这一点,是否有其他Perl模块可以做到这一点?
我使用JS自动化框架来测试iOS应用程序。在测试的中间,我需要向服务器创建POST请求以向用户支付一些钱,然后验证更改是否反映在UI中。
请求看起来像:wwww.testserver.com/userAddMoney?user_id=1&amount=999
但是要在服务器上进行授权,我需要将特殊参数传递给请求的标头:
标头: X-Testing-Auth-Secret:kI7wGju76kjhJHGklk76
提前致谢!
在C#中,它非常简单,并且谷歌不需要花费几分钟的时间:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(@"http://www.example.com?q=someValue");
request.Headers.Add("Authorization: OAuth realm=\"example.com\" oauth_consumer_key=\"BCqrstoO\" ... so on and so forth");
string resultString = "";
using (StreamReader read = new StreamReader(request.GetResponse().GetResponseStream(), true))
{
resultString = read.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)
试图在Ruby中做到这一点并不是那么直截了当(或者只是我缺少的一些愚蠢行为).我一直在寻找,我找到答案的最接近的事情是如何使用修改后的标头进行HTTP GET?并在Ruby中发送自定义标头.
所以我的问题,我想,归结为
到目前为止,我尝试了两个例子,这是我最近的非工作尝试:
headers = "Authorization: OAuth realm=\"example.com\" oauth_consumer_key=\"BCqrstoO\" ... so on and so forth"
uri = URI("www.example.com")
http = Net::HTTP.new(uri.host, uri.port)
http.get(uri.path, headers) do |chunk|
puts chunk
end
Run Code Online (Sandbox Code Playgroud) 我想向https服务器发送POST请求.
$data = 'name=value&name1=value1';
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('http://somewhere.com', $options);
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚在上面的POST示例代码中实现https选项.
有人可以解释一下如何做到这一点吗?我对使用Drupal的PHP编码很新,我绝对可以使用该指南.
我发现所有需要的是在协议中设置它.所以我得到了这段代码.
$data = 'access_token=455754hhnaI&href=fb&template=You have people waiting to play with you, play now!';
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('https://graph.facebook.com/1000721/notifications?', $options);
Run Code Online (Sandbox Code Playgroud)
它仍然无法正常工作.如果我通过Firefox发布https://graph.facebook.com/1000080521/notifications?access_token=45575FpHfhnaI&href=fb&template=You have people waiting to play with you, play now!它的工作原理.
我可能没有在Drupal中正确构建请求.
我究竟做错了什么?如何让我的代码工作?
我遇到了Flask视图的问题,该视图应该返回内容类型为"application/json"的响应以响应POST请求.具体来说,如果我这样做:
curl -v -d 'foo=bar' http://example.org/jsonpost
Run Code Online (Sandbox Code Playgroud)
对此观点:
@app.route('/jsonpost', methods=['GET', 'POST'])
def json_post():
resp = make_response('{"test": "ok"}')
resp.headers['Content-Type'] = "application/json"
return resp
Run Code Online (Sandbox Code Playgroud)
我得到某种连接重置:
* About to connect() to example.org port 80 (#0)
* Trying xxx.xxx.xxx.xxx... connected
* Connected to example.org (xxx.xxx.xxx.xxx) port 80 (#0)
> POST /routing/jsonpost HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: example.org
> Accept: */*
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
< Server: nginx/1.2.4
< Date: Thu, 27 Dec …Run Code Online (Sandbox Code Playgroud) 我无法让Apache HttpClient正确发送HttpPost标头.
我没有问题发送名称值对和诸如此类的东西,但每当我设置或添加POST标题时,它会在请求发生时消失.
我已经尝试了setHeader和addHeader,以及同时尝试这两个.
这是我的代码:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://posttestserver.com/post.php");
httppost.setHeader("Authorization: Bearer", accessToken);
httppost.addHeader("Authorization: Bearer", accessToken);
Log.d("DEBUG", "HEADERS: " + httppost.getFirstHeader("Authorization: Bearer"));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httppost, responseHandler);
Log.d("DEBUG", "RESPONSE: " + responseBody);
Run Code Online (Sandbox Code Playgroud)
此外,执行请求之前的调试语句打印出正确的标头,因此我知道它正在添加,然后稍后删除.
任何帮助将非常感激!
编辑:如果重要的话,这都在AsyncTask中运行.我认为没有,因为有一个NetworkOnMainThread异常抛出,但我认为值得一提.