所以我们有一个提供JSON的http资源.它增加了一个
Access-Control-Allow-Origin: *
Run Code Online (Sandbox Code Playgroud)
旗.所以这可以加载CORS ... 除了(所以我被告知)有一些IE9怪癖,这意味着它仍然无法在IE9中工作,但如果这是一个https资源它会工作.
因此,我们设置现有的https代理以包含此资源.只有那个https资源还添加了Access-Control-Allow-Origin:*标头,因此响应包含两个这样的标头.
而这似乎根本不起作用.从实验上看,如果我从"内部"http资源中删除标题,代理版本(现在只包含一个标题)确实有效.只需在Chrome,Firefox中使用jQuery CORS进行测试.
是对的吗?所以我需要做的是(有人)修复https代理以"设置"标题而不是"添加"吗?
我正在使用下面的代码下载一个文件,该工作很好,但问题是文件扩展名丢失,即使在压力下载后也是如此.我尝试将其更改为其他MIME类型,可能是什么问题,我该如何解决?
header('Content-Type: audio/mp3');
header("Content-Disposition: attachment; filename=$row[3]");
header("Content-Length: ".filesize("$row[1]$row[2]"));
$fp = fopen("$row[1]$row[2]", "r");
fpassthru($fp);
fclose($fp);
Run Code Online (Sandbox Code Playgroud)
注意:$ row数组中的值很好.
由于某种原因,我无法再访问"Content-Range"的响应头...因此,使用XHR无法确定资源的文件大小.我Refused to get unsafe header "Content-Range"在此行中遇到Chrome 错误:
var cr = this.getResponseHeader('Content-Range');
Run Code Online (Sandbox Code Playgroud)
这是CORS配置:
<?xml version="1.0" ?>
<CorsConfig>
<Cors>
<Origins>
<Origin>*</Origin>
</Origins>
<Methods>
<Method>GET</Method>
<Method>HEAD</Method>
<Method>DELETE</Method>
</Methods>
<ResponseHeaders>
<ResponseHeader>x-goog-meta-foo1</ResponseHeader>
<ResponseHeader>origin</ResponseHeader>
<ResponseHeader>range</ResponseHeader>
<ResponseHeader>Content-Range</ResponseHeader>
<ResponseHeader>Content-Length</ResponseHeader>
</ResponseHeaders>
<MaxAgeSec>1800</MaxAgeSec>
</Cors>
Run Code Online (Sandbox Code Playgroud)
CURL输出:
$ curl -H "Origin: http://peer5.com" http://commondatastorage.googleapis.com/peer5_vod/wind2_orig.mp4 -s -D - -o /dev/null
HTTP/1.1 200 OK
Server: HTTP Upload Server Built on May 8 2013 16:51:19 (1368057079)
Expires: Mon, 13 May 2013 09:47:40 GMT
Date: Mon, 13 May 2013 08:47:40 GMT
Cache-Control: public, max-age=3600, no-transform …Run Code Online (Sandbox Code Playgroud) 我完全陷入了我的一个显示错误的类中:
ResettableHttpServletResponse is not abstract and does not override abstract method getHeaderNames() in HttpServletResponse
Run Code Online (Sandbox Code Playgroud)
这是我的全部课程:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.exception.NestableRuntimeException;
@SuppressWarnings("deprecation")
public class ResettableHttpServletResponse implements HttpServletResponse, Resettable {
private interface ResponseOperation {
void apply();
}
private HttpServletResponse wrapped;
private List<ResponseOperation> operations;
private Locale locale;
private int bufferSize;
private String contentType;
private …Run Code Online (Sandbox Code Playgroud) 我需要允许一个名为"secretToken"的自定义标头.每次调用我的webapi,用户都应该传递这个标题.
我找了一种方法来做到这一点,但我找不到一个简单的方法.如何允许此自定义标头?
显然使用cookie对于在使用浏览器等时存储会话ID最有意义,但我使用Sails只是为了构建我的RESTful API,我想使用标题(X-Session-Identifier或其他东西)向Sails提供会话ID(这可以作为响应中的标题返回,所以我知道然后再发送什么).
我假设我需要编写一些中间件,但我无法在文档中的任何地方找到我可以进入的地方.
我是否需要删除connect的cookieSession中间件并将其替换为我自己的?
我正在尝试触发POST请求。我发送的数据是XML格式的(我通过JAXB进行此操作),但是我必须发送请求参数。我的问题与Content-Type有关(我在代码中添加了一些注释)。我应该使用哪一个?
见下面我的代码:
private V callAndGetResponse(K request, Class<K> requestClassType, Class<V> responseClassType) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(requestClassType, responseClassType);
Marshaller marshaller = jaxbContext.createMarshaller();
// set properties on marshaller
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, charset);
marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders", String.format(XML_HEADER_FORMAT, dtd));
marshaller.marshal(request, System.out);
URL wsUrl = new URL(primaryEndpointUrl);
HttpURLConnection connection = openAndPrepareConnection(wsUrl);
tryToMarshallWsRequestToOutputStream(request, marshaller, connection);
printDebug(connection);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Object response = unmarshaller.unmarshal(connection.getInputStream());
// cleanup
connection.disconnect();
return responseClassType.cast(response);
}
private HttpURLConnection openAndPrepareConnection(URL wsUrl) throws IOException {
HttpURLConnection connection = (HttpURLConnection) wsUrl.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Accept", "application/xml"); …Run Code Online (Sandbox Code Playgroud) 我正在使用Android注释,最近发现了一个错误Spring Rest Template使用导致EOFException,我不知道如何使用注释修复.我有帖子请求:
@Post("base/setItem.php")
Item setItem(Protocol protocol);
Run Code Online (Sandbox Code Playgroud)
现在,我该如何设置标题
headers.set("Connection", "Close");
Run Code Online (Sandbox Code Playgroud)
这个要求?
谢谢!
当我向服务器发送请求时
...
Response response = builder.method(req.getMethod(), Entity.entity(req, req.getMediaType())); // req.getMediaType() return MediaType.APPLICATION_XML
if(response.getStatus() != 200)
throw new CoreErrorException("core resulted error with status = " + response.getStatus());
T resp = response.readEntity(respType);
...
Run Code Online (Sandbox Code Playgroud)
泽西在最后一行抛出异常:
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/octet-stream
Run Code Online (Sandbox Code Playgroud)
我做了一些调查.首先,我抓住了这个回应:
Content-Length: 93
Date: Thu, 21 Nov 2013 12:53:46 GMT
Server: APP
<root>
<returncode>XXX</returncode>
<desc>some description</desc>
</root>
Run Code Online (Sandbox Code Playgroud)
标头不包含有关MediaType的任何信息.
实际上,当我尝试调用response.getMediaType()时,它返回null.
我想,那就是问题所在.Jersey无法检测到响应的MediaType并默认设置它("application/octet-stream").但实际上我的回答是XML.有什么方法可以告诉泽西岛吗?
我将使用正在使用Bearer身份验证的服务.我试图从Android取得它是徒劳的.这是我的代码.
String mytoken = "some token I am sure is right";
HttpClient witClient = new DefaultHttpClient();
Uri.Builder b = Uri.parse("www.somewebsite.com").buildUpon();
b.appendQueryParameter("q", "some query string");
String finalurl = b.build().toString();
HttpGet request = new HttpGet(new URI(finalurl));
request.setHeader("Authorization", "Bearer "+mytoken);
HttpResponse response = witClient.execute(request);
Run Code Online (Sandbox Code Playgroud)
服务器会返回一个错误,说明需要身份验证.显然,标题会以某种方式丢弃.
11-22 21:50:42.180: W/DefaultRequestDirector(3408): Authentication error: Unable to respond to any of these challenges: {bearer=Www-Authenticate: Bearer realm="OAuth required"}
Run Code Online (Sandbox Code Playgroud)
哪里错了
authentication android oauth http-headers apache-httpclient-4.x