标签: httpresponse

使用reportlab生成的pdf提供选项卡标题

这个问题很简单,但我找不到任何数据.当我使用reportlab生成pdf,将httpresponse作为文件传递时,配置为显示文件的浏览器会正确显示pdf.但是,选项卡的标题仍为"(匿名)127.0.0.1/whatnot",这对用户来说有点难看.

由于大多数网站能够以某种方式显示适当的标题,我认为这是可行的...是否有某种标题参数,我可以传递给PDF?或者响应的一些标题?这是我的代码:

def render_pdf_report(self, context, file_name):
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'filename="{}"'.format(file_name)

    document = BaseDocTemplate(response, **self.get_create_document_kwargs())
    #  pdf generation code
    document.build(story)
    return response
Run Code Online (Sandbox Code Playgroud)

python django pdf-generation reportlab httpresponse

11
推荐指数
3
解决办法
4247
查看次数

空响应和未找到响应的 HTTP 状态代码

我们正在实现基于 REST 的 Web 服务,并且对某些用例有一些疑问。

考虑有一个唯一的帐户,其中包含一些信息(例如添加到购物车信息)

  1. 如果不存在购物车信息,我们应该返回什么响应代码(例如 0)。我们的理解是返回 200 并返回空响应。
  2. 用户将购物车信息添加到其帐户,但购物车已被管理员删除。

应使用什么 HTTP 状态代码?

api rest web-services httpresponse http-status-code-301

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

.NET Core 中的 HttpContent.ReadAsAsync<T> 方法是否已被取代?

以下是指具有如下依赖项的 .NET Core 应用程序...

Microsoft.NETCore.App
Microsoft.AspNet.WepApi.Client (5.2.7)
Run Code Online (Sandbox Code Playgroud)

Microsoft.com 上有 2017 年 11 月的文档Call a Web API From a .NET Client (C#)

链接... https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

文档中包含 HTTP GET 的客户端调用。

    static HttpClient client = new HttpClient();
    static async Task<Product> GetProductAsync(string path)
    {
        Product product = null;
        HttpResponseMessage response = await client.GetAsync(path);
        if (response.IsSuccessStatusCode)
        {
            product = await response.Content.ReadAsAsync<Product>();
        }
        return product;
    }
Run Code Online (Sandbox Code Playgroud)

该值response.Content指的是一个HttpContent对象。截至 2020 年 7 月,HttpContent没有带有签名的实例方法ReadAsAsync<T>(),至少根据以下文档。然而,这个实例方法是有效的。

没有带有签名的实例方法的参考链接ReadAsAsync<T>()... https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpcontent?view=netcore-3.1

有一个HttpContentExtensions.ReadAsAsync<T>(myContent) …

c# httpresponse asp.net-core

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

解析XML HttpResponse

我正在尝试将我从HttpPost获取的XML HttpResponse解析为服务器(last.fm),用于last.fm android应用程序.如果我简单地将其解析为字符串,我可以看到它是一个普通的xml字符串,包含所有需要的信息.但我只是无法解析单个NameValuePairs.这是我的HttpResponse对象:

HttpResponse response = client.execute(post);
HttpEntity r_entity = response.getEntity();
Run Code Online (Sandbox Code Playgroud)

我尝试了两种不同的东西,而不是它们都有效.首先,我试图检索NameValuePairs:

List<NameValuePair> answer = URLEncodedUtils.parse(r_entity);
String name = "empty";
String playcount = "empty";
for (int i = 0; i < answer.size(); i++){
   if (answer.get(i).getName().equals("name")){
      name = answer.get(i).getValue();
   } else if (answer.get(i).getName().equals("playcount")){
      playcount = answer.get(i).getValue();
   }
}
Run Code Online (Sandbox Code Playgroud)

在此代码之后,name和playcount保持"空".所以我尝试使用XML Parser:

DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document answer = db.parse(new DataInputStream(r_entity.getContent()));
NodeList nl = answer.getElementsByTagName("playcount");
String playcount = "empty";
for (int i = 0; i < nl.getLength(); i++) {
   Node n = nl.item(i); …
Run Code Online (Sandbox Code Playgroud)

xml parsing android httpresponse http-post

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

HttpResponse使用android问题:执行总是导致异常?

我一直在研究一个Android项目,我想要一些API来获取信息.看起来这应该是非常基本的!

这是我的代码的一般要点:

private InputStream retrieveStream2(String url)
{
    DefaultHttpClient client = new DefaultHttpClient();

    HttpGet getRequest = new HttpGet(url);
    System.out.println("getRequest == " + getRequest);
    try {


        HttpResponse getResponse = client.execute(getRequest);//here is teh problem
        final int statusCode = getResponse.getStatusLine().getStatusCode();


        if (statusCode != HttpStatus.SC_OK)
        {
            Log.w(getClass().getSimpleName(),
                    "Error " + statusCode + " for URL " + url);
            return null;
        }

        HttpEntity getResponseEntity = getResponse.getEntity();
        return getResponseEntity.getContent();

    }
    catch (Exception e)
    {
        getRequest.abort();
        Log.w(getClass().getSimpleName(), "Error for URL, YO " + url, e);
    }
    return null; …
Run Code Online (Sandbox Code Playgroud)

java android httpresponse android-asynctask

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

在HttpResponse execute for android中,主机名可能不为null

我收到错误"目标主机不能为空,或在参数中设置".

  • I DO具有Internet权限在我的清单文件
  • 我把"http://"放在我的网址之前
  • 我会对 URL进行编码

这是我的代码:

   String url = "http://maps.google.com/maps/api/directions/json?origin=1600 Pennsylvania Avenue NW, Washington, DC 20500&destination=1029 Vermont Ave NW, Washington, DC 20005&sensor=false";
   HttpClient httpclient = new DefaultHttpClient();
   String goodURL = convertURL(url);//change weird characters for %etc
   HttpPost httppost = new HttpPost(goodURL);
   HttpResponse response = httpclient.execute(httppost);
Run Code Online (Sandbox Code Playgroud)

在第5行(上面的最后一行),我的程序抛出异常.这是确切的错误:

java.lang.IllegalArgumentException: Host name may not be null
Run Code Online (Sandbox Code Playgroud)

我在方法convertURL中编码我的字符串...

goodURL = http://maps.google.com/maps/api/directions/json?origin=3%20Cedar%20Ave%2c%20Highland%20Park%2c%20NJ%2008904&destination=604%20Bartholomew%20Road%2c%20Piscataway%2c%20New%20Jersey%2008854&sensor=false

有什么建议?谢谢!

android httpresponse http-post illegalargumentexception

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

System.getProperty("line.separator")对于Android来说是"\n"

我查询是否System.getProperty("line.separator")"\n"操作的Android网络相同.我的意思是说.我将从某个服务器获得行分离响应,所以最好使用System.getProperty("line.separator")"\n"

在Android中的字符串中使用\n重新提交回车/换行符,但仍然不确定网络操作.

java linux android httpresponse

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

是否允许HTTP 405状态响应具有正文?

我正在构建一个RESTful API.当客户端在不支持它的资源上使用不受支持的方法(如POST)时,我将返回一个405带有Allow列出允许方法的标头:

Status Code: 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS
Connection: keep-alive
Date: Mon, 08 Apr 2013 00:19:26 GMT
Transfer-Encoding: chunked
Run Code Online (Sandbox Code Playgroud)

是否允许有405响应的正文(提供错误消息)?

w3c的网站来看,不清楚是否允许一个机构405做出回应.

httpresponse http-status-codes

10
推荐指数
1
解决办法
4540
查看次数

如何从HttpResponseDecorator获取原始响应和URL

REST客户端HTTP生成器返回HttpResponseDecorator.如何从中获取原始响应(用于记录目的)?

编辑(一些代码可能很方便):

    withRest(uri: domainName) {
        def response = post(path: 'wsPath', query: [q:'test'])
        if (!response.success) {
            log.error "API call failed. HTTP status: $response.status"
            // I want to log raw response and URL constructed here
        }
Run Code Online (Sandbox Code Playgroud)

groovy httpresponse httpbuilder

10
推荐指数
1
解决办法
7936
查看次数

使用JSON处理GET和POST请求的简单Python服务器

我正在尝试创建一个简单的Python服务器来测试我的前端.它应该能够处理GET和POST请求.数据应始终采用JSON格式,直到它们转换为HTTP请求/响应.应调用具有相应名称的脚本来处理每个请求.

server.py

#!/usr/bin/env python

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
import json
import urlparse
import subprocess

class S(BaseHTTPRequestHandler):
    def _set_headers(self):
        self.send_response(200)
        self.send_header('Content-type', 'application/json')
        self.end_headers()

    def do_GET(self):
        self._set_headers()
        parsed_path = urlparse.urlparse(self.path)
        request_id = parsed_path.path
        response = subprocess.check_output(["python", request_id])
        self.wfile.write(json.dumps(response))

    def do_POST(self):
        self._set_headers()
        parsed_path = urlparse.urlparse(self.path)
        request_id = parsed_path.path
        response = subprocess.check_output(["python", request_id])
        self.wfile.write(json.dumps(response))

    def do_HEAD(self):
        self._set_headers()

def run(server_class=HTTPServer, handler_class=S, port=8000):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    print 'Starting httpd...'
    httpd.serve_forever()

if __name__ == "__main__":
    from sys import argv …
Run Code Online (Sandbox Code Playgroud)

python json httpresponse httprequest server

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