本文整理了Java中com.google.gwt.xhr.client.XMLHttpRequest.setRequestHeader()
方法的一些代码示例,展示了XMLHttpRequest.setRequestHeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLHttpRequest.setRequestHeader()
方法的具体详情如下:
包路径:com.google.gwt.xhr.client.XMLHttpRequest
类名称:XMLHttpRequest
方法名:setRequestHeader
[英]Sets a request header.
See http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method.
[中]设置请求头。
见http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method。
代码示例来源:origin: libgdx/libgdx
public void loadText (String url, final AssetLoaderListener<String> listener) {
XMLHttpRequest request = XMLHttpRequest.create();
request.setOnReadyStateChange(new ReadyStateChangeHandler() {
@Override
public void onReadyStateChange (XMLHttpRequest xhr) {
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
if (xhr.getStatus() != 200) {
listener.onFailure();
} else {
listener.onSuccess(xhr.getResponseText());
}
}
}
});
setOnProgress(request, listener);
request.open("GET", url);
request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
request.send();
}
代码示例来源:origin: libgdx/libgdx
public void loadText (String url, final AssetLoaderListener<String> listener) {
XMLHttpRequest request = XMLHttpRequest.create();
request.setOnReadyStateChange(new ReadyStateChangeHandler() {
@Override
public void onReadyStateChange (XMLHttpRequest xhr) {
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
if (xhr.getStatus() != 200) {
listener.onFailure();
} else {
listener.onSuccess(xhr.getResponseText());
}
}
}
});
setOnProgress(request, listener);
request.open("GET", url);
request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
request.send();
}
代码示例来源:origin: com.google.gwt/gwt-servlet
private void setHeaders(XMLHttpRequest xmlHttpRequest)
throws RequestException {
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> header : headers.entrySet()) {
try {
xmlHttpRequest.setRequestHeader(header.getKey(), header.getValue());
} catch (JavaScriptException e) {
throw new RequestException(e.getMessage());
}
}
} else {
xmlHttpRequest.setRequestHeader("Content-Type",
"text/plain; charset=utf-8");
}
}
}
代码示例来源:origin: net.wetheinter/gwt-user
private void setHeaders(XMLHttpRequest xmlHttpRequest)
throws RequestException {
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> header : headers.entrySet()) {
try {
xmlHttpRequest.setRequestHeader(header.getKey(), header.getValue());
} catch (JavaScriptException e) {
throw new RequestException(e.getMessage());
}
}
} else {
xmlHttpRequest.setRequestHeader("Content-Type",
"text/plain; charset=utf-8");
}
}
}
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
private void setHeaders(XMLHttpRequest xmlHttpRequest)
throws RequestException {
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> header : headers.entrySet()) {
try {
xmlHttpRequest.setRequestHeader(header.getKey(), header.getValue());
} catch (JavaScriptException e) {
throw new RequestException(e.getMessage());
}
}
} else {
xmlHttpRequest.setRequestHeader("Content-Type",
"text/plain; charset=utf-8");
}
}
}
代码示例来源:origin: stackoverflow.com
void postJson(Map<String, String> map, String url) {
XMLHttpRequest request = new XMLHttpRequest();
// Post asynchronously
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
// Encode the data as JSON before sending
String mapAsJson = JSON.stringify(toJsObject(map));
request.send(mapAsJson);
}
jsweet.lang.Object toJsObject(Map<String, String> map) {
jsweet.lang.Object jsObject = new jsweet.lang.Object();
// Put the keys and values from the map into the object
for (Entry<String, String> keyVal : map.entrySet()) {
jsObject.$set(keyVal.getKey(), keyVal.getValue());
}
return jsObject;
}
代码示例来源:origin: com.badlogicgames.gdx/gdx-backend-gwt
public void loadText (String url, final AssetLoaderListener<String> listener) {
XMLHttpRequest request = XMLHttpRequest.create();
request.setOnReadyStateChange(new ReadyStateChangeHandler() {
@Override
public void onReadyStateChange (XMLHttpRequest xhr) {
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
if (xhr.getStatus() != 200) {
listener.onFailure();
} else {
listener.onSuccess(xhr.getResponseText());
}
}
}
});
setOnProgress(request, listener);
request.open("GET", url);
request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
request.send();
}
代码示例来源:origin: threerings/playn
xhr.open(req.method(), req.url);
for (Header header : req.headers) {
xhr.setRequestHeader(header.name, header.value);
throw new UnsupportedOperationException("Raw bytes not currently supported in HTML5.");
xhr.setRequestHeader("Content-Type", req.contentType());
xhr.send(req.payloadString);
} else {
代码示例来源:origin: thothbot/parallax
public void loadText (final FileListener<String> listener) {
XMLHttpRequest request = XMLHttpRequest.create();
request.setOnReadyStateChange(new ReadyStateChangeHandler() {
@Override
public void onReadyStateChange (XMLHttpRequest xhr) {
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
if (xhr.getStatus() != 200) {
listener.onFailure();
} else {
listener.onSuccess(xhr.getResponseText());
}
}
}
});
setOnProgress(request, listener);
request.open("GET", getUrl());
request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
request.send();
}
代码示例来源:origin: io.playn/playn-html
xhr.open(req.method(), req.url);
for (Header header : req.headers) {
xhr.setRequestHeader(header.name, header.value);
if (req.payloadBytes != null) throw new UnsupportedOperationException(
"Raw bytes not currently supported in HTML5.");
xhr.setRequestHeader("Content-Type", req.contentType());
xhr.send(req.payloadString);
} else {
代码示例来源:origin: playn/playn
xhr.open(req.method(), req.url);
for (Header header : req.headers) {
xhr.setRequestHeader(header.name, header.value);
if (req.payloadBytes != null) throw new UnsupportedOperationException(
"Raw bytes not currently supported in HTML5.");
xhr.setRequestHeader("Content-Type", req.contentType());
xhr.send(req.payloadString);
} else {
代码示例来源:origin: org.atmosphere/atmosphere-gwt-client
try {
xmlHttpRequest.open("GET", getUrl(connectionCount));
xmlHttpRequest.setRequestHeader("Accept", "application/comet");
xmlHttpRequest.setOnReadyStateChange(new ReadyStateChangeHandler() {
@Override
代码示例来源:origin: com.vaadin.external.atmosphere/atmosphere-gwt-client
try {
xmlHttpRequest.open("GET", getUrl(connectionCount));
xmlHttpRequest.setRequestHeader("Accept", "application/comet");
xmlHttpRequest.setOnReadyStateChange(new ReadyStateChangeHandler() {
@Override
代码示例来源:origin: com.googlecode.gwtquery/gwtquery
if (headers != null) {
for (String headerKey : headers.getFieldNames()) {
xmlHttpRequest.setRequestHeader(headerKey, String.valueOf(headers.get(headerKey)));
xmlHttpRequest.setRequestHeader("Content-Type", ctype);
内容来源于网络,如有侵权,请联系作者删除!