response

爬虫(十六):Scrapy框架(三) Spider Middleware、Item Pipeline

我怕爱的太早我们不能终老 提交于 2020-01-06 14:09:16
1. Spider Middleware Spider Middleware是介入到Scrapy的Spider处理机制的钩子框架。 当Downloader生成Response之后,Response会被发送给Spider,在发送给Spider之前,Response会首先经过Spider Middleware处理,当Spider处理生成Item和Request之后,Item Request还会经过Spider Middleware的处理。 Spider Middleware有三个作用: 我们可以在Downloader生成的Response发送给Spider之前,也就是在Response发送给Spider之前对Response进行处理。 我们可以在Spider生成的Request发送给Scheduler之前,也就是在Request发送给Scheduler之前对Request进行处理。 我们可以在Spider生成的Item发送给Item Pipeline之前,也就是在Item发送给Item Pipeline之前对Item进行处理。 1.1 使用说明 需要说明的是,Scrapy其实已经提供了许多Spider Middleware,它们被SPIDER_MIDDLEWARES_BASE这个变盘所定义。 SPIDER_MIDDLEWARES_BASE变量的内容如下: { 'scrapy

JAVA GET response for HTTP POST Request

半腔热情 提交于 2020-01-06 08:32:32
问题 How to get the status code or something better to know if an message was sent? I already do this, but off course it don't work. httppost.setEntity(new StringEntity(message.toString())); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); String status = response.getStatusLine().toString(); Log.d(CLASS_TAG + "showOnScreenMessage", "Message sent! "); Log.d(CLASS_TAG + "showOnScreenMessage", "Status : " + status ); // if response == 201 , the message has be

Rails 5.2 API - Returning enum value in JSON

让人想犯罪 __ 提交于 2020-01-06 08:18:08
问题 I currently have a postgres enum type setup in my user columns as roles . It works as intended like so. Example: class User < ApplicationRecord enum role: { admin: "Admin", viewer: "Viewer" } end And the JSON response returns it as: { "id": 1, "role": "admin" } However, the role attribute is returning the key instead of the enum value. Is there a solution for this? 回答1: Give this a try def as_json(options = {}) super.tap do |hash| hash['role'] = User::roles[role] end end 回答2: I'd do this way.

C#调用RESTful API

依然范特西╮ 提交于 2020-01-06 08:12:57
如今非常多的网络服务都用RESTful API来实现。 比方百度的搜索推广API介绍使用Rest原因: REST+JSON风格的API相比SOAP+XML,优点是:调用更加灵活。也更easy扩展;JSON格式传输信息比XML降低约30%的数据量,效率更高。因此建议开发人员使用REST风格的API 。 查找了非常多调用Rest API网络碎片资料,总是无法理解或者生效。 以下摘一点认为有效果的作为參考吧。 http://www.makeyuan.com/2014/02/27/1117.html 利用该文中Post方法来调用百度搜索推广的API。尽管代码乱。可是总算成功了,以下即是代码: public static void send() { string url = "https://api.baidu.com/json/sms/v3/AccountService/getAccountInfo"; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "POST"; request.ContentType = "application/json"; string data = "{\n\"header\": {\n\"token\": \

Session variable empty in iis7 application

試著忘記壹切 提交于 2020-01-06 08:06:32
问题 I have an asp.net application that uses ajax. I want to be able to pass data from one page to another so I store what I want in a session variable and redirect the response to the destination page where i retrieve what i want for further processing. I use: Response.Redirect(path, false) Everything works fine until I try to publish to my staging iis7 server. My session variable always returns empty. But if I try to navigate to the page from within the iis server itself (via right click on the

Mock Server利器 - Moco

不问归期 提交于 2020-01-06 07:40:24
转载请标明出处: http://blog.csdn.net/shensky711/article/details/52770686 本文出自: 【HansChen的博客】 Moco介绍 Moco独立运行所需环境 如何运行Moco 启动http服务 启动https服务 Moco HTTPs API配置 如何在配置文件添加注释 约定请求Body 约定接口的uri 约定请求参数 约定请求方法 约定HTTP版本 约定请求头部 约定cookie 约定请求form 约定以指定xml作为请求body 用xpath对请求进行匹配 约定以指定json作为请求body 用正则表达式对请求进行匹配 匹配操作 设置Response content 设置Response 状态码 设置Response HTTP版本 设置Response 头部 设置重定向 设置cookie 挂载文件 template的用法 Moco在单元测试中使用 Moco的不足 Moco介绍 在开发过程中,经常会使用到一些http网络接口,而这部分功能通常是由第三方开发团队或者是后端同事进行开发的,在我们开发时不能给我们提供服务,更有甚者,要集成的服务在开发时还不存在。这为我们的联调和测试造成了麻烦,常见的解决方案是搭建一个web server。 为什么要开发Moco这个框架? 具体到模拟服务上,处理的手法也是各种各样

Moco 详解

岁酱吖の 提交于 2020-01-06 07:36:26
一、下载及安装: 运行环境: JAVA环境 linux 下载地址: https://github.com/dreamhead/moco 下载下来的是一个jar包,如:moco-runner-0.12.0-standalone.jar 把这个jar包上传到linux服务器上,然后在与moco-runner-0.12.0-standalone.jar同级的目录下创建 foo.json 文件: [ { "response" : { "text" : "Hello, Moco" } } ] Moco的运行非常简单,只需要一行命令即可: java -jar <path-to-moco-runner> http -p <monitor-port> -c < configuration -file> <path-to-moco-runner> :moco-runner-0.11.0-standalone.jar包的路径 <monitor-port> :http服务监听的端口 <configuration -file> :配置文件路径 java -jar moco-runner-0.12.0-standalone.jar http -p 9999 -c foo.json 通过浏览器访问服务器的9999端口: 返回正确就说明Moco服务搭建成功了。 虽然说服务运行没问题了,但是总觉得启动和停止很麻烦

request

删除回忆录丶 提交于 2020-01-06 00:55:23
目录 1.安装 2.引入 3.请求方式 3.1 GET请求 3.1.1 基本请求 3.1.2 GET请求的主要参数 3.2 POST请求 3.2.1 使用POST请求模拟登陆 4.响应 4.1 响应参数 5.其他 requests官方中文文档: https://requests.readthedocs.io/zh_CN/latest/ 1.安装 pip install requests 2.引入 import requests # 发送请求获取响应内容 response = request.get('http://www.baidu.com') 3.请求方式 3.1 GET请求 HTTP默认的请求方法就是GET 没有请求体 数据必须在1K之内 GET请求数据会暴露在浏览器的地址栏中 GET请求常用的操作: 在浏览器的地址栏中直接给出URL,那么就一定是GET请求 点击页面上的超链接也一定是GET请求 提交表单时,表单默认使用GET请求,但可以设置为POST 3.1.1 基本请求 import requests # 发送请求获取响应内容 response = request.get('http://www.baidu.com') print(response.text) 3.1.2 GET请求的主要参数 url 请求资源的路径 headers User-Agent

The message received from the server could not be parsed

孤街醉人 提交于 2020-01-06 00:21:07
Response.Redirect("~/MainScreen.aspx") ‘成功 Server.Transfer("~/MainScreen.aspx") ‘失败 Sys.WebForms.PageRequestManagerParserErrorException:The message received from the server count not be parsed.Common causes for this error are when the response is modified by calls to response.Write(),response filters,HttpModules,or server trace is enabled. Details:Error parsing near '|<html> <head> ================== 此前,我定义了web.config的customError 段,使系统中一旦发生异常,就转到自定义的错误页面, 但是这样做有一个很严重的问题, 就是无法看到异常的信息, 最近我越来越觉得无法忍受这一点, 于是换了一种做法, 在global.asax中, 自定义Application_Error 事件,在这里可以得到异常的信息, 然后把它传递给错误页面, 最终用Server.Transfer

http协议状态码大全

允我心安 提交于 2020-01-05 22:23:56
100 Continue:初始的请求已经接受,客户应当继续发送请求的其余部分。 101 Switching Protocols:服务器将遵从客户的请求转换到另外一种协议。 200 OK:一切正常,对GET和POST请求的应答文档跟在后面。如果不用SetStatus设置状态代码,Servlet默认使用202状态代码。 201 Created 服务器已经创建了文档,Location头给出了它的URL。 202 Accepted:已经接受请求,但处理尚未完成。 203 Non-Authoritative Information:文档已经正常地返回,但一些应答头可能不正确,因为使用的是文档的拷贝。 204 No Content:没有新文档,浏览器应该继续显示原来的文档。如果用户定期地刷新页面,而Servlet可以确定用户文档足够新,这个状态代码是很有用的。 205 Reset Content:没有新的内容,但浏览器应该重置它所显示的内容。用来强制浏览器清除表单输入内容。 206 Partial Content:客户发送了一个带有Range头的GET请求,服务器完成了它。 300 Multiple Choices:客户请求的文档可以在多个位置找到,这些位置已经在返回的文档内列出。如果服务器要提出优先选择,则应该在Location应答头指明。 301 Moved Permanently