【问题标题】:WLClient addGlobalHeader does not workWLClient addGlobalHeader 不起作用
【发布时间】:2015-02-09 13:03:40
【问题描述】:

我正在尝试设置全局标头以将特定的安全信息发送到后端适配器。这似乎不适用于使用 Objective-C 的原生 iOS 应用程序。我敢肯定,我错过了一些东西。

这是我的简单示例:

NSLog(@"Invoking Procedure...");
WLProcedureInvocationData *myInvocationData = [[WLProcedureInvocationData alloc] initWithAdapterName:@"RSSReader" procedureName:@"getStories"];
MyInvokeListener *invokeListener = [[MyInvokeListener alloc] initWithController: self];
[[WLClient sharedInstance] addGlobalHeader:@"header1" headerValue:@"header1"];
[[WLClient sharedInstance] invokeProcedure:myInvocationData withDelegate:invokeListener];

发送的标头根本没有改变。

【问题讨论】:

  • 你是想用这个来改变 Cookie 头,还是只是随机的头?

标签: objective-c ibm-mobilefirst mobilefirst-adapters mobilefirst-studio


【解决方案1】:

您如何检查标头是否已发送?
哪个版本的 MobileFirst?

我为重现所做的步骤:

  • 运行 MobileFirst Studio 6.3.0.00.20150130-1638
  • 我已经下载了 ios 示例中的调用 (https://ibm.biz/BdEw79)
  • 在我的doInvokeProcedure 中添加了您的addGlobalHeader 行:

    - (IBAction)doInvokeProcedure:(UIButton *)sender {
    [self updateView:@"Invoking Procedure..."];
    NSLog(@"Invoking Procedure...");
    WLProcedureInvocationData *myInvocationData = [[WLProcedureInvocationData alloc] initWithAdapterName:@"RSSReader" procedureName:@"getStories"];
    MyInvokeListener *invokeListener = [[MyInvokeListener alloc] initWithController: self];
    [[WLClient sharedInstance] addGlobalHeader:@"header1" headerValue:@"header1"];
    [[WLClient sharedInstance] invokeProcedure:myInvocationData withDelegate:invokeListener];
    
    }
    
  • 在 WireShark 中捕获流量:

    POST /InvokingAdapterProceduresNative/apps/services/api/InvokingAdapterProceduresiOS/iOSnative/query HTTP/1.1
    Host: localhost:10080
    X-Requested-With: XMLHttpRequest
    User-Agent: InvokingAdapterProceduresiOS/1.0 (iPhone Simulator; iOS 8.1; Scale/2.00)/WLNativeAPI/6.3.0.00.20150130-1638
    Cookie: WL_PERSISTENT_COOKIE=279ea643-f731-4c5e-8a59-74ed4842b3d8; JSESSIONID=0000x8PNWpTDWKW73FnPaw9oTAm:42599173-098f-4ab1-b562-68c6a8e1f345
    WL-Instance-Id: 7kreem49ql20l2pdf1fuq9q0kc
    x-wl-clientlog-osversion: 8.1
    x-wl-clientlog-env: iOSnative
    header1: header1
    x-wl-clientlog-deviceId: 18A44BA7-4DF9-411B-9577-5954C8E44921
    x-wl-clientlog-model: x86_64
    x-wl-analytics-tracking-id: 6D6B72FD-820C-4EF8-AE45-205723E464FF
    Content-Length: 112
    Connection: keep-alive
    x-wl-clientlog-appname: InvokingAdapterProceduresiOS
    x-wl-platform-version: 6.3.0.00.20150130-1638
    Accept-Language: en
    x-wl-clientlog-appversion: 1.0
    Accept: */*
    Content-Type: application/x-www-form-urlencoded; charset=utf-8
    Accept-Encoding: gzip, deflate
    x-wl-app-version: 1.0
    

注意中间的header1: header1

【讨论】:

  • Nathan,我使用了完全相同的示例,再次运行它,我也可以在 WireShark 中看到标题。奇怪的是,标题没有在输出中列出,如您在此处看到的:
  • { "接受语言" = en; "User-Agent" = "InvokingAdapterProceduresiOS/1.0 (iPhone Simulator; iOS 8.1; Scale/2.00)/WLNativeAPI/6.3.0.00.20141121-0732"; "X-Requested-With" = XMLHttpRequest; "x-wl-app-version" = "1.0"; "x-wl-clientlog-appname" = InvokingAdapterProceduresiOS; “x-wl-clientlog-appversion”=“1.0”; “x-wl-clientlog-deviceId”=“310E52D3-9D07-4EFD-B19B-1FBA9EC70503”; “x-wl-clientlog-env”=iOSnative; “x-wl-clientlog-model”=“x86_64”; “x-wl-clientlog-osversion”=“8.1”; “x-wl-平台版本”=“6.3.0.00.20141121-0732”; }
  • “输出”是什么意思。输出什么?你是如何生成这个 JSON 字符串的?
  • 这个 xcode 日志很可能是在添加自定义标头之前发生的。我相信自定义标头是在发送请求之前的最后一分钟添加的。
猜你喜欢
  • 1970-01-01
  • 2016-03-13
  • 1970-01-01
  • 1970-01-01
  • 2016-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-28
相关资源
最近更新 更多