【问题标题】:Consume an esv bible web service使用 esv 圣经网络服务
【发布时间】:2013-06-26 06:26:39
【问题描述】:

我将在我的个人网站上使用ESV Bible. 的公共网络服务。

我已经获得了 API 密钥。对于一般测试,“IP”可以是关键。它有一个asp代码。

<%
 'Reference Search
  key = "IP"
  strSearch = "John 1"
  passage = Server.URLEncode(strSearch)
  options = "include-passage-references=true"
  set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
  objHTTP.open "GET", "www.esvapi.org/v2/rest/passageQuery?key=" & _
  key & "&passage=" & passage & "&" & options, false
  objHTTP.send
  Response.Write(objHTTP.responseText)
 %>

但是我使用asp.net mvc 4,我要在视图中按下一个按钮然后弹出一个新窗口或创建一个html网页来显示响应。

如何修改代码?

【问题讨论】:

    标签: jquery json wcf asp.net-mvc-4 wcf-rest


    【解决方案1】:

    您可以为此使用 WebClient,来自 System.Net 命名空间

    var client = new WebClient();
    var query = string.Format("www.esvapi.org/v2/rest/passageQuery?key={0}&passage={1}&options={2}", "IP", Server.UrlEncode(strSearch),options);
    var result = client.DownloadString(query);
    

    我还没有通过 IDE 处理这个,所以你可能需要检查一下

    【讨论】:

    • 我必须将这些代码放在 Razor 中,添加 @?你把响应作为字符串返回?
    • 在控制器中,您可以选择您想要的显示方式,例如从操作返回内容结果并使用 ajax 使用它,或者将其作为视图模型传递并显示在在那里。
    猜你喜欢
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多