本文介绍了如何使用VB.NET将JSON发布到特定的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB.NET中有关Web服务的新手.我正在制作一个可以与JIRA对话的桌面应用程序( http://www.atlassian.com/软件/jira/).他们提供了我决定使用的REST API.第一步是登录,他们说...

I'm a newbie about web services in VB.NET. I'm making a desktop application that will talk to JIRA (http://www.atlassian.com/software/jira/). They provided a REST api that I decided to use. The first step is to login which they say that...

要登录JIRA,您需要以JSON格式发布用户名和密码..."

{用户名":管理员",密码":管理员"}

此网址...

https://addressgoeshere (我们正在使用https)

https://addressgoeshere (we are using https)

有人可以给我提供示例代码来执行此操作,以便为您提供指南和一个良好的开端吗?

Can someone provide me a sample code to do this so I can have a guide and a good start?

推荐答案

以下是有效发布json的代码.变量res能够使您对查询进行响应

Here is the code to post json effectively. The variable res is able to give you the responce to your query

记住要导入

  • System.Net
  • System.IO
  • System.text

通过使用

Imports

,然后是导入名称

要绕过过期的ssl证书,请检查以下内容: http://blog.jameshiggs.com/2008/05/01/c-how-to-accept-an-invalid-ssl-certificate-programmatically/

to bypass expired ssl certificate check this: http://blog.jameshiggs.com/2008/05/01/c-how-to-accept-an-invalid-ssl-certificate-programmatically/

Private Function SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String
  Dim response As String
  Dim request As WebRequest

  request = WebRequest.Create(uri)
  request.ContentLength = jsonDataBytes.Length
  request.ContentType = contentType
  request.Method = method

  Using requestStream = request.GetRequestStream
    requestStream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
    requestStream.Close()

    Using responseStream = request.GetResponse.GetResponseStream
      Using reader As New StreamReader(responseStream)
        response = reader.ReadToEnd()
      End Using
    End Using
  End Using

  Return response
End Function

使用此功能

Dim data = Encoding.UTF8.GetBytes(jsonSring)
Dim result_post = SendRequest(uri, data, "application/json", "POST")

-编辑-

链接页面现已过期.这是一个有效的存档副本:

The linked page has expired by now. Here is a working archived copy:

"> https://web.archive.org/web/20110924191356/http://blog.jameshiggs.com/2008/05/01/c-how-to-以编程方式接受无效的SSL证书/

这篇关于如何使用VB.NET将JSON发布到特定的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:37