如何让JSF发送http头
Content-Type: application/xhtml+xml;charset=UTF-8而不是当前
Content-Type: text/html;charset=UTF-8?
添加以下代码段web.xml无效.
<mime-mapping>
<extension>xhtml</extension>
<mime-type>application/xhtml+xml</mime-type>
</mime-mapping>
Run Code Online (Sandbox Code Playgroud)
我的示例文件 webapp/sample.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:outputLabel value="Hello, world"/>
</f:view>
</html>
Run Code Online (Sandbox Code Playgroud)
环境:
JSF 2.2,WildFly 8.2
当我要创建2GB文件的zip文件时,如何找出问题.
错误
file_get_contents():内容从2147483648截断到2147483647字节
致命错误:内存不足(分配2151677952)(试图分配18446744071562067968字节)
我正在使用专用服务器并已设置memory_limit,max_execution_time,max_upload_filesize,max_post_size.但它不适合我.请检查我的代码,让我知道我做错了什么 -
$zip = new ZipArchive();
# create a temp file & open it
$tmp_file = tempnam('.','');
$zip->open($tmp_file, ZipArchive::CREATE);
# loop through each file
foreach($files as $file){
# download file
$download_file = file_get_contents($file_path.'/'.$file);
#add it to the zip
$zip->addFromString(basename($file_path.'/'.$file),$download_file);
}
# close zip
$zip->close();
$zip_name = $last_seg.'.zip';
# send the file to the browser as a download
header("Content-disposition: attachment; filename=$zip_name");
header('Content-type: application/zip');
readfile($tmp_file);
Run Code Online (Sandbox Code Playgroud) 我正在尝试向$.getJSON以下URL 发出简单请求:http:
//dev.markitondemand.com/Api/v2/InteractiveChart/json?parameter =%7B%22Normalized%22%3Afalse%2C%22NumberOfDays%22%3A7% 2C%22DataPeriod%22%3A%22Day%22%2C%22Elements%22%3A%5B%7B%22Symbol%22%3A%22NUS%22%2C%22Type%22%3A%22price%22%2C%22Params% 22%3A%5B%22C%22%5D%7D%5D%7D
请求的资源上不存在"Access-Control-Allow-Origin"标头.原产地" 的http://本地主机:1337 "因此不允许访问.
我的代码很简单:
var ticker = "CRR";
var url = "http://dev.markitondemand.com/Api/v2/InteractiveChart/json?parameters=%7B%22Normalized%22%3Afalse%2C%22NumberOfDays%22%3A7%2C%22DataPeriod%22%3A%22Day%22%2C%22Elements%22%3A%5B%7B%22Symbol%22%3A%22" + ticker + "%22%2C%22Type%22%3A%22price%22%2C%22Params%22%3A%5B%22c%22%5D%7D%5D%7D";
$.getJSON(url, function(data) {
console.log(data);
}).success(function() {
$('#show-data').html("Successfully retrieved data.");
}).error(function() {
$('#show-data').html("Service Unavailable.");
});
Run Code Online (Sandbox Code Playgroud)
它没有运行任何错误或成功函数,而当我尝试时,我得到同样的东西$.ajax.就我的设置而言,我正在尝试一个MEN项目,所以我的localhost上有Mongo,Express和Node.js.任何帮助,将不胜感激.
我正在使用Django开发一个新网站,我遇到了ajax请求的问题.我一直在谷歌搜索并阅读了很多帖子和文章(大多数解释相同).
问题:执行了ajax调用,我在视图中收到了请求,但request.is_ajax()返回false.据我所知,request.is_ajax()检查HTTP_X_REQUESTED_WITH标头的值,但我在请求标头中看不到它,因此我无法在视图中检查is_ajax().
HTML表单:
<form id="search-form" method="get" action="/search/">
<input type="text" id="search" name="search" placeholder="Search">
<button id="btn-search" >SEARCH</button>
</form>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
$('#search-form').submit(function(e) {
e.preventDefault();
$.ajax({
url : $('#search-form').attr('action'),
type:'GET',
data : {
'search' : $('#search').val()
},
success: function(data, e) {
alert("SUCCESS")
},
error: function(data) {
alert("ERROR");
},
});
})
Run Code Online (Sandbox Code Playgroud)
我的看法:
def search(request):
if request.is_ajax():
print "SOMETHING"
if request.GET:
import requests
url = API_END_POINT + '&name=Bruce+Springsteen'
response = requests.get(url).json()
return HttpResponse(json.dumps(response), content_type='application/json')
return render(request, 'core/search.html')
Run Code Online (Sandbox Code Playgroud)
这是我在Chrome网络标签中看到的内容:
General
Remote Address:127.0.0.1:8000
Request URL:http://localhost:8000/search/?search=Bruce+Springsteen
Request Method:GET
Status Code:200 …Run Code Online (Sandbox Code Playgroud) 我的架构中有三个应用程序.
它们位于同一台服务器上,但具有不同的端口号.
A - Token Application (port 4444) - Asp.net WebApi
B - API Application (port 3333) - Asp.net WebApi
C - UI Application (port 2222) - AngularJS App.
Run Code Online (Sandbox Code Playgroud)
申请流程如下
1- UI项目从令牌应用程序获取令牌(它需要Windows身份验证.)Ex: awxrsdsaWeffs12da
2- UI应用程序将此标记放入自定义标头,该标头名为"accessToken"
例如:accessToken: awxrsdsaWeffs12da
3- UI应用程序向API Application Ex发送请求: http:myaddress:3333/api/TheRestServiceHere
UI应用程序获得401错误.哪个发送OPTIONS方法.(我想预检问题)
在我的web api项目中,我启用了如下所示的Cors.
public static void Register(HttpConfiguration config)
{
....
//CORS
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
....
}
Run Code Online (Sandbox Code Playgroud)
配置
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
//CORS
var cors = new …Run Code Online (Sandbox Code Playgroud) 如何在openshift门户上启用HTTP严格传输安全性?我正在开发一个php应用程序,不太确定在何处进行此设置.我相信我需要访问Apache配置文件来实现这一点 - 我不认为openshift允许.
我正在编写一个角度应用程序,我正在尝试使用该$http服务连接到我们的API .
$http.post('https://backend-test/***/v001/login', {'userName': 'admin', 'password': 'passtest'}, {headers: {'Accept': 'application/json', 'Content-Type': 'application/json'}}).then(function success(response) {
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
但是,我继续收到此错误:
XMLHttpRequest无法加载 https:// backend-test /***/v001/login.预检的响应具有无效的HTTP状态代码403
它似乎发送OPTIONS请求而不是POST请求:
请求方法:选项
奇怪的是,当我使用这个工具时它正常工作:
有什么想法吗?
情景:
首先,请考虑我正在使用HttpClient课程,不是WebRequest,我知道这里有很多相关问题,但所有答案都是针对WebRequest的.
我制作了一个Web Api应用程序,以这种方式设置以下标题,以便下载.txt文件:
resp.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/plain");
resp.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = _datacontext.GetAppConfig("814FileNameHeader") + DateTime.Now.ToString("yyyyMMdd") + ".txt"
};
resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
Run Code Online (Sandbox Code Playgroud)
之后我从其他应用程序中创建了一个HttpClient来连接到这个方法.
一切正常,检索200和文件的内容.但我无法获取标题以读取文件名.
TRIES MADE:
使用REST客户端我可以阅读以下标头属性:
内容 - 处理:附件; 文件名= 814Entes_PG_20160114.txt
从代码我可以调试它,我发现标题是在"invalidHeaders",但我无法达到值:
题:
我如何设置这个并毫无疑问地从客户那里获得?
更新:
这些是我尝试获取标题:原始:
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(uri);
string authentication = string.Concat(authenticationArgs[0], ":", authenticationArgs[1]);
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Basic " + Base64Encode(authentication));
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, "Report/" + type);
req.Content = …Run Code Online (Sandbox Code Playgroud) 有没有办法输出一个CFHTTP电话的原始html ?我试图了解一些标头身份验证信息是如何发生的.
我对浏览器插件或代码更新持开放态度,无论哪个帮助我看看cfhttp通话过程中发生了什么.
例如:
<cfhttp method="get" url="https://test-ows01.mywebsite.com/criminal_api//1.0/service/requests" result="orderList">
<cfhttpparam type="HEADER" name="Authorization" value="Basic #ToBase64("bearer:4EC8B09D3F911764B1DCD3EFA38DFB31")#">
</cfhttp>
Run Code Online (Sandbox Code Playgroud)
上面的调用在发生时会是什么样子.
我在React中使用axios发出了这个POST请求:
postRunSimulation(simulationId) {
var requestAnalysis = `${configFile.web.backend}analysis/${simulationId}/run`;
return axios.post(requestAnalysis)
.then(function (response) {
return response.headers;
}, function(error) {
throw new Error('An error occurred : ' + error.status + ' - ' + error.statusText);
});
},
Run Code Online (Sandbox Code Playgroud)
我得到的对象有一个headers属性,但它是空的.如果我和Postman打同一个电话,我会收到标题.我究竟做错了什么 ?
http-headers ×10
ajax ×2
angularjs ×2
c# ×2
cors ×2
jquery ×2
.net ×1
attachment ×1
axios ×1
cfhttp ×1
coldfusion ×1
content-type ×1
django ×1
file ×1
https ×1
javascript ×1
jsf-2 ×1
json ×1
memory-limit ×1
openshift ×1
php ×1
post ×1
reactjs ×1
security ×1
wildfly-8 ×1
xhtml ×1
zip ×1