标签: httpresponse

从liferay门户获取HttpServletResponse

我试图从liferay门户获取HttpServletResponse.我也在使用icefaces.

PortletResponse response1 = (PortletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
        HttpServletResponse response = (HttpServletResponse)response1;
Run Code Online (Sandbox Code Playgroud)

我得到以下例外:

Caused by: java.lang.ClassCastException: com.liferay.portlet.RenderResponseImpl cannot be cast to javax.servlet.http.HttpServletResponse
Run Code Online (Sandbox Code Playgroud)

jsf icefaces httpresponse liferay

2
推荐指数
1
解决办法
8393
查看次数

如何在JAX-RS中设置HTTP错误代码

我有一个使用jar-rs的web服务.如何将自定义http错误代码抛出到调用应用程序?

谢谢

java weblogic jax-rs httpresponse

2
推荐指数
1
解决办法
1465
查看次数

为什么没有`Set-Cookie`标题作为回应?

我发现有时浏览器无法从我的网站上获取cookie,所以我curl用来检查标题,信息是:

C:\Documents and Settings\jack>curl http://localhost -I
HTTP/1.1 200 OK
Expires: Thu, 01-Jan-1970 00:00:00 GMT
Set-Cookie: SCALAEYE_SESSION="a57cf8ebdfc379da91ad17d1d1eac706c25ae4c3-%3Citems%3E%3C%2Fitems%3E";Path=/
Set-Cookie: SCALAEYE_FLASH="%3Citems%3E%3C%2Fitems%3E";Path=/
Content-Length: 121665
Server: Jetty(6.1.26)
Run Code Online (Sandbox Code Playgroud)

但是当我使用浏览器IE6Firefox访问时,标题是:

Response Headersview source
Date    Fri, 08 Apr 2011 08:48:09 GMT
Transfer-Encoding   chunked
Server  Jetty(6.1.26)
Run Code Online (Sandbox Code Playgroud)

你可以看到没有Set-Cookie标题,这会产生问题.我的服务器是Jetty 6.1.26.为什么他们的回答不同?哪里错了?以及如何解决它?

curl httpresponse chunked setcookie

2
推荐指数
1
解决办法
2万
查看次数

在POST之后在PHP中设置Location标头时,请避免使用HTTP 302响应代码

我需要201 Created为POST请求放置一个Response代码和一个Location头,但由于某种原因,我仍然得到302响应.

这就是我所拥有的:

header('HTTP/1.1 201');
header("Location: ..."); // The new resource URL
header('Content-type: application/json; charset=utf-8');
echo $response;
exit;
Run Code Online (Sandbox Code Playgroud)

我已经尝试删除内容类型,echo并且exit没有任何运气,仍然得到302.我读到我需要指定两个标题,但这就是我正在做的事,没有运气.我也尝试过:

header("Location: ...", TRUE, 201);
Run Code Online (Sandbox Code Playgroud)

没什么,仍然有302 :(

有人知道我没看到什么吗?

谢谢.

php post http httpresponse http-headers

2
推荐指数
1
解决办法
6211
查看次数

Django - 是否可以从视图中的函数进行重定向?

我尝试调用一个检查规则的函数,如果规则未满足,我想跳过其余的视图代码,只返回一个HttpResponse错误.

我想将所有转义逻辑放在一个函数中,因为我需要在我的项目中的几个点上.

我试着这样做:

def myView(request):

    checkFunction()
Run Code Online (Sandbox Code Playgroud)

和:

def checkFunction():
    #do stuff
    return HttpResponse(status=403)
Run Code Online (Sandbox Code Playgroud)

但它只是不起作用(难怪)......

任何想法如何做到这一点?

谢谢

罗恩

django return view httpresponse decorator

2
推荐指数
1
解决办法
1844
查看次数

WCF这可能是由于服务端点绑定不使用HTTP协议

Default.aspx.cs

WCFService.Service1Client client = new WCFService.Service1Client();
string stream = client.JsonSerializeFromDatabase();
client.Close();
WCFService.Service1Client client2 = new WCFService.Service1Client();
foreach (WCFService.Person in client2.JsonDeserializeFromDatabase(stream)) 
Run Code Online (Sandbox Code Playgroud)

Service1.svc.cs

public IList<Person> JsonDeserializeFromDatabase(string value)
{
    MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(value));
    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<Person>));
    IList<Person> tableData = (IList<Person>)ser.ReadObject(ms);
    ms.Close();
    ms.Dispose();

    return tableData;
}
Run Code Online (Sandbox Code Playgroud)

IService1.cs

[OperationContract]
IList<Person> JsonDeserializeFromDatabase(string value);
Run Code Online (Sandbox Code Playgroud)

服务器Web.config

    <httpRuntime maxRequestLength="8192"/>
</system.web>
...
<system.serviceModel>
<services>
    <service name="TestWCF.Service1" behaviorConfiguration="TestWCF.Service1Behavior">
        <endpoint address="" binding="wsHttpBinding" contract="TestWCF.IService1">
            <identity>
                <dns value="localhost"/>
            </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
</services>
<behaviors>
<serviceBehaviors>
    <behavior name="TestWCF.Service1Behavior">
    <serviceMetadata …
Run Code Online (Sandbox Code Playgroud)

wcf httpresponse wcf-binding wcf-data-services json-deserialization

2
推荐指数
1
解决办法
3万
查看次数

尝试读取httpResponse时套接字关闭异常

我有一个方法连接发送数据到Web服务并获得响应如下:

public HttpResponse sendXMLToURL(String url, String xml, String httpClientInstanceName) throws IOException {
    HttpResponse response = null;

    AndroidHttpClient httpClient = AndroidHttpClient.newInstance(httpClientInstanceName);
    HttpPost post = new HttpPost(url);

    StringEntity str = new StringEntity(xml);
    str.setContentType("text/xml");
    post.setEntity(str);

    response = httpClient.execute(post);

    if (post != null){
        post.abort();
    }
    if (httpClient !=null){
        httpClient.close();
    }

    return response;
}
Run Code Online (Sandbox Code Playgroud)

然后,在我的片段的AsyncTask中,我尝试使用getEntity()读取响应:

HttpResponse response = xmlUtil.sendXMLToURL("url", dataXML, "getList");

            //Check if the request was sent successfully
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                // Parse result to check success
                responseText = EntityUtils.toString(response.getEntity());

                if (!xmlParser.checkForSuccess(responseText, getActivity())){ …
Run Code Online (Sandbox Code Playgroud)

sockets android httpresponse androidhttpclient

2
推荐指数
1
解决办法
3529
查看次数

HttpContext.Current.Response.AddHeader()未设置Content-Type标头

我正在使用第三方软件从html文档渲染PDF.我创建了一个小型测试项目,并使用我能够从目录中读取html文档的OnClick事件<asp:Button>并将其呈现为PDF而没有任何问题.

响应创建如下:

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.AddHeader("Content-Disposition", 
    String.Format("{0}; filename=Test.pdf;", "inline" ));
HttpContext.Current.Response.BinaryWrite(pdfBuffer);
HttpContext.Current.ApplicationInstance.CompleteRequest();
Run Code Online (Sandbox Code Playgroud)

当我查看Chrome中的响应时,我可以看到正确设置了Content-Type:

内容处置:内联; 文件名= HtmlToPdf.pdf;

内容长度:101482

内容类型:应用程序/ PDF

我试图将上述内容转移到我当前的项目中.唯一的区别是,<asp:Button>我在DevExpress网格视图中使用自定义按钮而不是一个.我最初在回调面板中处理了自定义按钮单击,但未设置Content-Type.在Chrome中查看响应证明了这一点:

内容处置:内联; 文件名= 5.pdf;

内容编码:gzip

内容长度:149015

内容类型:text/plain的; 字符集= utf-8的

我也尝试过使用该gvDocuments.CustomButtonCallback += new ASPxGridViewCustomButtonCallbackEventHandler(gvDocuments_CustomButtonCallback);事件,但仍没有设置Content-Type.

任何人都有任何想法,为什么我不能在上述场景中设置Content-Type?

c# pdf asp.net webforms httpresponse

2
推荐指数
1
解决办法
1万
查看次数

controller httpresponsemessage好的,但是ajax总是触发fail方法

我遇到了一个奇怪的问题.

我使用MVC(而不是web api),因此控制器继承自Controller,而不是ApiController.

我用ajax调用控制器动作(POST),动作返回HttpResponseMessage

这是我得到的回应:

{"readyState":4,"responseText":"StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StringContent, Headers:\r\n{\r\n  Location: /\r\n  Content-Type: application/json; charset=utf-8\r\n}","status":200,"statusText":"OK"}
Run Code Online (Sandbox Code Playgroud)

但是,当ajax接收数据时,它会触发fail方法.

这是ajax函数:

$.ajax({
    url: "someurl",
    type: "post",
    data: data,
    dataType: "json",
    contentType: "application/json; charset=utf-8"
}).done(function (data) {
    alert(data.responseText);
    window.location.href = "redirect to some url";
}).fail(function (data) {
    alert("error");<-- this one is called even when i set HttpStatusCode.OK
    alert(JSON.stringify(data));
}).always(function () {
});
Run Code Online (Sandbox Code Playgroud)

这是一个简化的控制器动作:

[HttpPost]
[AllowAnonymous]
public HttpResponseMessage Index(HttpRequestMessage request, Login model)
//public HttpResponseMessage Index(Login …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc jquery json httpresponse asp.net-web-api

2
推荐指数
1
解决办法
8781
查看次数

如何将Content-Length,Content-Type和Last-Modified添加到HTTP响应消息头中

如何使用.net将Content-Length,Content-Type和Last-Modified添加到HttpResponseMessage标头。

添加这些字段后,我需要将所有这些值手动附加到响应中,我需要从服务器返回响应。我试图以休闲的方式添加这些字段

httpResponse.Content.Headers.Add("Content-Length", item.Size.ToString());
httpResponse.Content.Headers.Add("Content-Type", item.ContentType);
Run Code Online (Sandbox Code Playgroud)

但是它抛出异常

“你调用的对象是空的”。

如果我这样添加

httpResponse.Headers.Add("Content-Length", item.Size.ToString());
httpResponse.Headers.Add("Content-Type", item.ContentType);
Run Code Online (Sandbox Code Playgroud)

我收到了错误的错误

“错误的标头名称。请确保请求标头与HttpRequestMessage一起使用,响应标头与HttpResponseMessage一起使用,内容标头与HttpContent对象一起使用。”

请任何人帮我将这些字段添加到HttpResponsesMessage中。

.net c# httpresponse

2
推荐指数
1
解决办法
1万
查看次数