我编写了一个使用 Java 网络服务的 WCF C# 客户端:
var client = new abcClient("abc");
var response = client.AbcTransaction(msg);
Run Code Online (Sandbox Code Playgroud)
来自 web.config的WCF 绑定信息是:
<customBinding>
<binding name="abcSOAP">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport requireClientCertificate="true" />
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
它看起来很简单,对吧?...确实,SoapFaults 很容易使用:
HTTP/1.1 500 Internal Server Error
Content-Length: 783
Content-Type: application/soap+xml;charset=UTF-8
Server: Microsoft-IIS/8.0
Date: Mon, 18 Nov 2013 14:06:18 GMT
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body><soap:Fault>...
Run Code Online (Sandbox Code Playgroud)
但是,网络服务在multipart/related content-type 中发送“常规”响应:
HTTP/1.1 200 OK
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:c79210c3-bbef-4aa3-82ae-6a20c7a96564"; start="<root.message@cxf.apache.org>"; start-info="application/soap+xml"
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
Date: Mon, …Run Code Online (Sandbox Code Playgroud) 我在jetty web服务器(还有tomcat)上运行基于注释的Spring Rest服务。控制器代码是:
\n\n@RequestMapping(method = RequestMethod.POST, value = { "/ssrfeed/exec/",\n "/query/exec" }, consumes = { "application/xml", "text/xml",\n "application/x-www-form-urlencoded" }, produces = {\n "application/xml;charset=UTF-8", "text/xml;charset=UTF-8",\n "application/x-www-form-urlencoded;charset=UTF-8" })\n @ResponseBody\n protected String getXmlFeed(HttpServletRequest request,\n @PathVariable String serviceName, @RequestBody String xmlReq) {\n\n //code....\n return appXMLResponse;\n }\nRun Code Online (Sandbox Code Playgroud)\n\n问题是控制器返回的响应 xml 包含一些字符,例如 \xc3\xa4 \xc3\xb6 \xc3\xbc (Umlaute)。在浏览器上呈现时的响应给出解析错误:
\n\nXML Parsing Error: not well-formed\nLocation: //localhost:8083/MySerice/ssrfeed/exec/\nLine Number 18111, Column 17:\n<FIRST_NAME>Tzee rfista</FIRST_NAME>\n----------------^\nRun Code Online (Sandbox Code Playgroud)\n\n(\xc3\xbc 的位置出现一个小三角形)
\n\nThe expected is : <FIRST_NAME>Tzee\xc3\xbcrfista</FIRST_NAME>\nRun Code Online (Sandbox Code Playgroud)\n\n我已尝试以下解决方案,但问题仍然存在。
\n\n尝试使用过滤器参考technowobble上给出的解决方案
将字符集传递给 …
也许是个愚蠢的问题。
我最近一直在玩 Node.js,喜欢设置服务器和发出请求等是多么容易。我还没有尝试过,但想知道如何将数据从一个请求转发到另一台服务器,并有第二个服务器向客户端发送响应。
这可能吗?
IE
客户端 -> 服务器 A -> 服务器 B -> 客户端 X
让我感到困惑的是如何发送给同一个客户?此信息应该出现在请求标头中,不是吗?是否需要将该信息转发给服务器 B?
我现在的情况是在 Node.js 服务器上接受请求,并且希望将一些数据转发到我创建的 Laravel API 并将响应发送到客户端表单。
感谢您的回答,
马特
Jack Lindamood 发表了一篇出色的博客文章《如何在 Go 1.7 中正确使用 context.Context》,可归结为以下报价:
Context.Value 应该提供信息,而不是控制。如果您正确使用 context.Value,这是我认为应该指导的主要原则。context.Value 的内容适用于维护者而不是用户。决不应该要求输入记录或预期结果。
目前,我正在使用Context以下信息传输:
RequestID它在客户端生成并传递到 Go 后端,并且仅通过命令链,然后再次插入响应中。如果没有RequestID响应,客户端就会崩溃。
SessionID标识 WebSocket 会话,当在异步计算(例如工作队列)中生成某些响应时,这一点很重要,以便标识应在哪个 WebSocket 会话上发送响应。
当非常认真地对待这个定义时,我会说两者都违反了意图,context.Context但话又说回来,它们的值在发出整个请求时不会改变任何行为,它仅在生成响应时相关。
还有什么选择呢?在服务器 API 中拥有context.Contextfor 元数据实际上有助于维护精益方法签名,因为这些数据实际上与 API 无关,但仅对传输层很重要,这就是为什么我不愿意创建类似请求结构的内容:
type Request struct {
RequestID string
SessionID string
}
Run Code Online (Sandbox Code Playgroud)
并使其成为每个 API 方法的一部分,该方法仅在发送响应之前传递。
我希望以单一方法处理我的所有回复。目的是在响应代码不是 3 时调用服务,当响应代码为 3 时,我打算先刷新令牌,然后再调用相同的服务。
我创建了一个Basecallback类来捕获一个方法,但我看不到日志,也无法捕获断点。
BASECALLBACK.class
public class BaseCallBack<T> implements Callback<T> {
@Override
public void onResponse(Call<T> call, Response<T> response) {
if (!response.isSuccessful()){
Log.d("BaseCallback","Response Fail");
}
}
@Override
public void onFailure(Call<T> call, Throwable t) {
t.toString();
}
}
Run Code Online (Sandbox Code Playgroud)
调用方法
ApiManager.getInstance().getUsers().enqueue(new BaseCallBack<List<User>>() {
@Override
public void onResponse(Call<List<User>> call, Response<List<User>> response) {
if (response.isSuccessful()){
}
}
@Override
public void onFailure(Call<List<User>> call, Throwable t) {
}
});
Run Code Online (Sandbox Code Playgroud)
我只想处理我的服务单一方法。
我尝试返回为 json 添加属性,我在用户模型中使用以下方法获得该属性,但我不断收到
"message": "Malformed UTF-8 characters, possibly incorrectly encoded",
"exception": "InvalidArgumentException",
"file": "/var/www/timetool/vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php",
Run Code Online (Sandbox Code Playgroud)
代码
/**
* @return string
*/
public function getAvatarImageAttribute($value)
{
if($this->hasMedia('avatar')) {
$image = $this->getMedia('avatar');
$img = \Intervention\Image\ImageManagerStatic::make($image[0]->getPath())->encode('data-url');
}
elseif (isset($this->blob->dokument)) {
$img = 'data:image/jpeg;base64,'. base64_encode($this->blob->document);
} else {
$img = '';
}
return $img;
}
Run Code Online (Sandbox Code Playgroud)
在控制器中我有
return \Response::json($users, 200, array('Content-Type' => 'application/json;charset=utf8'), JSON_UNESCAPED_UNICODE);
Run Code Online (Sandbox Code Playgroud) 第一个想法是使用 anHttpInterceptor但clone(...)方法的签名不包含该observe选项。除了定义{ observe: 'response' }为每个请求的选择,我没有看到另一种尚未...
那么,是否有(如果有的话)全局设置{ observe: 'response' }选项的方法,例如通过?HttpInterceptor
clone(update: {
headers?: HttpHeaders;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
body?: T | null;
method?: string;
url?: string;
setHeaders?: {
[name: string]: string | string[];
};
setParams?: {
[param: string]: string;
};
}): HttpRequest<T>;
Run Code Online (Sandbox Code Playgroud) 我想在(角度 5)中制作一个这样的可观察对象。如何responseType在 Angular 6 中声明?
Angular 5 代码:
public ExportSomeThing(
ano: number
): Observable<IDownloadArquivo> {
let q = this.http
.get(this.apiUrl + ano + '/pordia/excel', {
responseType: ResponseContentType.Blob // <<<-- This code
}).map((res) => {
Run Code Online (Sandbox Code Playgroud)
我的角度 6 代码:
public MyExport(
ano: number
): Observable<IXpto> {
let q = this.http
.get( this.api_rul + ano + '/some_path/', {
responseType: "ResponseContentType.Blob" // <<<--- error here !!!
}).map((res) => {
Run Code Online (Sandbox Code Playgroud)
错误是:
[ts]
Argument of type '{ responseType: "ResponseContentType.Blob"; }' is not assignable to …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我自己的 Java 实体类和 Jackson 注释来生成 JSON 响应。null我的 JSON 响应中必须有两个键值,但如果我将它们设置为它们null,它们就会从 JSON 中消失。不幸的是,我只能使用 Jackson 版本 1.9.13。
我已经尝试将值设置为null,使用
@JsonSerialize(include = JsonSerialize.Inclusion.ALWAYS)
Run Code Online (Sandbox Code Playgroud)
我的响应实体:
public class Response {
@JsonProperty("data")
private Data data;
@JsonProperty("error")
private Error error;
public Data getData() {
return data;
}
public void setData(PgSoftAuthData data) {
this.data = data;
}
public Error getError() {
return error;
}
public void setError(PgSoftError error) {
this.error = error;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试生成这样的响应:
Data data = new Data();
data.setName("Name");
data.setTime(null); // This …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Express 发送带有换行符的字符串。
const express = require('express');
const app = express();
persons = [//...];
app.get('/info', (req,res) => {
res.send(`Phonebook has info for ${persons.length} people.
${Date()}`);
});
Run Code Online (Sandbox Code Playgroud)
我在网上读到,从 ES6 开始,反引号可用于构造多行,但它似乎不起作用。
我想要的输出是:
Phonebook has info for 4 people.
Thu Oct 10 2019 18:54:01 GMT-0700 (Pacific Daylight Time)
Run Code Online (Sandbox Code Playgroud)
我还尝试了以下方法:
app.get('/info', (req,res) => {
res.send(`Phonebook has info for ${persons.length} people.\n${Date()}`);
});
Run Code Online (Sandbox Code Playgroud)
我在网上读到你也可以只使用 '\n' 但这也不起作用。
我究竟做错了什么?我一直在遵循我在网上找到的建议,但我无法显示新的一行。
response ×10
angular ×2
java ×2
node.js ×2
android ×1
angular5 ×1
angular6 ×1
attributes ×1
blob ×1
c# ×1
content-type ×1
express ×1
go ×1
http ×1
httpclient ×1
interceptor ×1
jackson ×1
json ×1
laravel-5 ×1
laravel-5.5 ×1
line-breaks ×1
middleware ×1
newline ×1
null ×1
performance ×1
resttemplate ×1
retrofit ×1
retrofit2 ×1
server ×1
spring ×1
utf-8 ×1
wcf ×1
websocket ×1