Dashcode 3.0,数据源+非表单 POST 请求?

发布于 2024-08-03 02:35:53 字数 1209 浏览 3 评论 0原文

问题简述:在 Dashcode 3.0 中,如何告诉数据源发送 POST 请求,例如:

  url:
     https://example.com/xml
  method:
     POST
  HTTPBody:
     <?xml version='1.0'?>
     <request command='list'>
        <parameter keyword='id' value='trogdor' />
     </request>

Snow Leopard 中新的 Dashcode 3.0 非常棒。我对“数据源”特别感兴趣——您可以在其中提供返回 XML 或 JSON 的 URL。 Dashcode 获取数据,然后允许您在响应片段和 UI 之间建立连接 - 很像 Interface Builder。

我发现的所有示例都使用 HTTP GET 请求。但我的提要必须通过 POST 访问。 DC.AjaxController 有一个“method”属性——易于设置为POST。它还有一个“参数”属性——模仿基于表单的帖子。问题是,我的请求不是来自表格。我将描述我在 Objective-C 中所做的工作。我想让同样的东西像仪表板和 Safari 小部件一样工作。

  NSMutableURLRequest *theRequest=[NSMutableURLRequest
     requestWithURL:[NSURL URLWithString:@"https://example.com/xml"]];
  [theRequest setHTTPMethod:@"POST"];

  NSString *postString =
     @"<?xml version='1.0'?><request command='list'><parameter keyword='id' value='trogdor' /></request>";

  [theRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];

  NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

手动完成就可以了——我不必使用高超的 Dashcode 3.0 视觉连接,但这会很有趣。

Question in brief: In Dashcode 3.0, how do I tell a Data Source to send a POST request like:

  url:
     https://example.com/xml
  method:
     POST
  HTTPBody:
     <?xml version='1.0'?>
     <request command='list'>
        <parameter keyword='id' value='trogdor' />
     </request>

The new Dashcode 3.0 in Snow Leopard is fantastic. I'm especially excited about "data sources" -- where you can provide a URL that returns XML or JSON. Dashcode fetches the data, then allows you to draw connections between pieces of the response and your UI -- much like Interface Builder.

All of the examples I've found use an HTTP GET request. But my feed must be accessed via POST. The DC.AjaxController has a "method" attribute -- easy to set to POST. It also has a "parameters" attribute -- to mimic a form-based post. The trouble is, my request is not from a form. I'll describe what I have working in Objective-C. I'd like to make the same thing work as a Dashboard and Safari widget.

  NSMutableURLRequest *theRequest=[NSMutableURLRequest
     requestWithURL:[NSURL URLWithString:@"https://example.com/xml"]];
  [theRequest setHTTPMethod:@"POST"];

  NSString *postString =
     @"<?xml version='1.0'?><request command='list'><parameter keyword='id' value='trogdor' /></request>";

  [theRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];

  NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

It would be ok to do it manually -- I don't have to use the whiz-bang Dashcode 3.0 visual connections, but it would be fun.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文