我正在使用Ruby on Rails 3,我正在尝试设置JSON/XML响应的值.
在我的控制器中我有
respond_to do |format|
format.xml { render :xml => @user.to_xml }
format.json { render :json => @user.to_json }
end
Run Code Online (Sandbox Code Playgroud)
当我为JSON/XML发出HTTP GET请求时,会设置这些常用值
header:
date:
- Fri, 18 Feb 2011 18:02:55 GMT
server:
- Apache ...
etag:
- "\"0dbfd0ec23934921144bd57d383db443\""
cache-control:
- max-age=0, private, must-revalidate
x-ua-compatible:
- IE=Edge
x-runtime:
- "0.033209"
status:
- "200"
transfer-encoding:
- chunked
content-type:
- application/json; charset=utf-8 #or application/xml; charset=utf-8
http_version: "1.1"
message: OK
read: true
Run Code Online (Sandbox Code Playgroud)
我想添加/设置header值并添加像message2或的新参数header2.
我怎么能用format.json/xml …
我正在尝试向浏览器发送HTTP响应
char *reply =
"HTTP/1.1 200 OK\n"
"Date: Thu, 19 Feb 2009 12:27:04 GMT\n"
"Server: Apache/2.2.3\n"
"Last-Modified: Wed, 18 Jun 2003 16:05:58 GMT\n"
"ETag: \"56d-9989200-1132c580\"\n"
"Content-Type: text/html\n"
"Content-Length: 15\n"
"Accept-Ranges: bytes\n"
"Connection: close\n"
"\n"
"sdfkjsdnbfkjbsf";
int sd = socket(PF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr;
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(8081);
addr.sin_addr.s_addr = INADDR_ANY;
if(bind(sd,&addr,sizeof(addr))!=0)
{
printf("bind error\n");
}
if (listen(sd, 16)!=0)
{
printf("listen error\n");
}
for(;;)
{
int size = sizeof(addr);
int client = accept(sd, &addr, &size);
if …Run Code Online (Sandbox Code Playgroud) 我很难获得基于suds的python SOAP客户端来解析响应:客户端构造正确并且解析WSDL就好了.据我所知,WSDL中没有导入,所以这似乎不是一个典型的ImportDoctor问题.
WSDL的相关位:
<xsd:complexType name="getFontsRequest">
<xsd:sequence>
<xsd:element name="UserID" type="xsd:int" maxOccurs="1" minOccurs="1"></xsd:element>
<xsd:element name="TAWSAccessKey" type="xsd:string" maxOccurs="1" minOccurs="1"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="getFontsResponse">
<xsd:sequence>
<xsd:element name="UserID" type="xsd:int"></xsd:element>
<xsd:element name="Status" type="xsd:string"></xsd:element>
<xsd:element name="Fonts" type="tns:FontType[]"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="FontType">
<xsd:sequence>
<xsd:element name="ID" type="xsd:int"></xsd:element>
<xsd:element name="Name" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)
我的代码:
self.soap_client = Client(settings.WSDL_URL)
self.factory = self.soap_client.factory
self.service = self.soap_client.service
# ...
getFontsRequest = self.factory.create('getFontsRequest')
getFontsRequest.UserID = settings.WS_UID
getFontsRequest.TAWSAccessKey = settings.WS_KEY
self.service.getFonts(getFontsRequest)
Run Code Online (Sandbox Code Playgroud)
最后一行抛出此异常:
...
File "/usr/local/Cellar/python/2.7.1/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 63, in resolve
raise TypeNotFound(qref)
TypeNotFound: Type not …Run Code Online (Sandbox Code Playgroud) 我想要做的是使用ffmpeg制作视频的缩略图.视频数据在HTTP请求中接收,然后通过管道传输到ffmpeg.问题是,一旦ffmpeg子进程退出,我就无法发回响应.
这是代码:
var http = require('http'),
sys = require('sys'),
child = require('child_process')
http.createServer(function (req, res) {
im = child.spawn('ffmpeg',['-i','-','-vcodec','mjpeg','-ss','00:00:03','-vframes','1','-s','100x80','./thumb/thumbnail.jpg']);
im.on('exit', function (code, signal) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('{"success":true}\n');
});
req.connection.pipe(im.stdin);
}).listen(5678, "127.0.0.1");
Run Code Online (Sandbox Code Playgroud)
问题是调用:
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('{"success":true}\n');
Run Code Online (Sandbox Code Playgroud)
什么都不做,客户端永远不会收到回复.
我有一个用php生成的网页,表格放在div中.表单使用Ajax提交并在服务器端验证.如果出现错误,则div的内容将替换为带有错误消息的更新表单.如果表单中没有错误,我想从ajax响应重新加载整个页面,而不仅仅是div.有谁知道这是怎么做到的吗?我已经尝试发送位置标题,但它将新页面放在div中.我也尝试过javascript window.location,但是当收到ajax响应时,我不知道是不是很热.我没有使用jQuery所以我想在计划javascript和/或php中这样做.提前致谢!
我需要检查网址内容类型是否为pdf?我有一个工作代码,但我想知道什么是最好的方式来检查我有什么.我不需要显示pdf,只需要检查内容类型是否为pdf? 注意:此方法将使用不同的url多次调用,因此我不确定是否需要关闭响应.
这是我的代码.
private bool IsValid(string url)
{
bool isValid = false;
var request = (HttpWebRequest)WebRequest.Create(url);
var response = (HttpWebResponse)request.GetResponse();
if(response.StatusCode == HttpStatusCode.OK && response.ContentType == "application/pdf")
{
isValid = true;
}
response.Close();
return isValid;
}
Run Code Online (Sandbox Code Playgroud) 当我们在java中已经有response.setContentType时,我是否知道使用response.addHeader ...我找不到合适的解决方案.
<% response.addHeader("Content-Disposition","attachment;filename=Report.xls"); %>
<% response.setContentType("application/vnd.ms-excel"); %>
Run Code Online (Sandbox Code Playgroud)
这里的上述第二个语句足以将响应作为excel格式.哪个场景我需要使用response.addHeader?
请 ...
我已经实现了Web服务MyWebServiceImpl,如:
@WebServiceClient(//my parameters//)
@HandlerChain(file = "handlers.xml")
public class MyWebServiceImpl {...}
Run Code Online (Sandbox Code Playgroud)
我也有像MyWebService这样的接口
@WebService(//my parameters//)
@XmlSeeAlso({
com.my.ObjectFactory.class,
com.my.second.ObjectFactory.class,
com.my.third.ObjectFactory.class
})
public interface MyWebService {...}
Run Code Online (Sandbox Code Playgroud)
我想使用Soap处理程序获得响应,因此我创建了handlers.xml,LoggingHandler.然后我尝试执行我的测试类我得到错误:
javax.xml.ws.WebServiceException: {http://service.ws.my.com/}MyWebServiceImpl is not a valid service. Valid services are: {http://service.ws.my.com/}myWebService
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.my.ws.service.MyWebServiceImpl.<init>(MyWebServiceImpl.java:46)
at test.MainTest.<init>(MainTest.java:354)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at …Run Code Online (Sandbox Code Playgroud) 在通过最新的IRC RFC进行调整之后我感到有些困惑,RFC在5.1节规定响应005用于退回消息,但每当我连接到IRC服务器时,005数字响应用于ISUPPORT ,因为它描述了这里.
我错误地认为RFC2812是最新的?或者,在将005更改为RPL_ISUPPORT时,我是否遗漏了一些附录?
我也发现了这个早期的SO 问题(它来自2011年,但仍然比我能找到的任何文档更新)其中005的回复被称为"地图",这是现在完整的第三件事.
为了增加混乱,我在这里发现了另一个2011年的SO问题,其中有人指出RFC2812不是实现的,而应该遵循RFC 1459,但是在第6节:回复 0-199的回复丢失了,我我无法在文档中的任何位置找到它们.
我希望有人可以为我提供一些关于IRC文档噩梦的信息.
我在Chrome开发工具中看到的响应标头与Angular 2在Chrome控制台中显示的响应标头不匹配.
执行后只显示Content-Type标题:
this.http.get(tempUrl).map(res=>{
console.log("csrf received");
console.log(res);
})
Run Code Online (Sandbox Code Playgroud)