Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 无法将post值发送到特定url?_.net_Dotnetnuke - Fatal编程技术网

.net 无法将post值发送到特定url?

.net 无法将post值发送到特定url?,.net,dotnetnuke,.net,Dotnetnuke,我正在开发一个DotNetNuke模块,并创建了两个模块。第一个模块接受发布的数据。第二模块向第一模块发送post数据。我无法将帖子数据发送到特定的URL。接收器模块应将数据存储到数据库中。下面是我在这篇文章中使用的代码 string myParameters = "EmailId=" + tbEmail.Text; WebClient wc = new WebClient(); wc.Headers["Content-type"] = "application/x-www-form

我正在开发一个DotNetNuke模块,并创建了两个模块。第一个模块接受发布的数据。第二模块向第一模块发送post数据。我无法将帖子数据发送到特定的URL。接收器模块应将数据存储到数据库中。下面是我在这篇文章中使用的代码

  string myParameters = "EmailId=" + tbEmail.Text;
  WebClient wc = new WebClient();
  wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
  string HtmlResult = wc.UploadString(UrlKeyGen, myParameters);
任何帮助都将不胜感激。
提前谢谢。

我不能说我熟悉您尝试使用的WebClient类。以下是我用于发布的代码:

        Public Function UrlPOST(ByVal URL As String, ByVal POSTdata As String) As String
        Dim rtnValue As StringBuilder = New StringBuilder()
        Dim isValidParams As Boolean = True

        ' check for url
        If (URL.Length < 10) Then
            isValidParams = False
            Throw New Exception("URL = '" + URL + "' is not a valid URL.")
        ElseIf (URL.IndexOf("://") <= 0) Then
            isValidParams = False
            Throw New Exception("URL = '" + URL + "' is not a valid URL. URL must include protocol, e.g. 'http://'")
        End If

        If (isValidParams) Then
            Dim result As WebResponse = Nothing
            Try
                ' setup WebRequest object
                Dim request As WebRequest = WebRequest.Create(URL)
                request.Method = "POST"
                request.Timeout = 5000
                request.ContentType = "application/x-www-form-urlencoded"

                ' add payload for POST to request stream
                Dim SomeBytes As Byte()
                SomeBytes = Encoding.UTF8.GetBytes(POSTdata)
                request.ContentLength = SomeBytes.Length
                Dim newStream As Stream = request.GetRequestStream()
                newStream.Write(SomeBytes, 0, SomeBytes.Length)
                newStream.Close()

                ' POST data and get response
                result = request.GetResponse()
                Dim objSD As StringDictionary = URIQueryParser(result.ResponseUri.Query())

                rtnValue.Append(TranslateErrorCode(objSD("codes")))

            Catch ex As Exception
                Dim ex1 As New Exception("Exception Posting to External Site. Posting String: " & POSTdata & "... " & ex.ToString)
                LogException(ex1)
                '               Dim objEventLog As New Services.Log.EventLog.EventLogController
                '               objEventLog.AddLog("WebRequest Exception: ", "Exception Posting to External Site: " & ex.ToString  & ", Posting String: " & PostData, PortalSettings, UserId, Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT)
                Throw ex1
            Finally
                If (Not (result Is Nothing)) Then
                    result.Close()
                    result = Nothing
                End If
            End Try
        End If
        Return rtnValue.ToString()
    End Function

    Private Function URIQueryParser(ByVal UriQuery As String) As System.Collections.Specialized.StringDictionary
        Dim sd As New StringDictionary
        Dim objStringArray() As String
        If (Not UriQuery Is Nothing) AndAlso UriQuery.Length > 0 Then
            UriQuery = UriQuery.Substring(1)
            objStringArray = UriQuery.Split("&"c)
            For Each s As String In objStringArray
                sd.Add(s.Split("="c)(0), s.Split("="c)(1))
            Next
        End If

        Return sd
    End Function
公共函数UrlPOST(ByVal URL作为字符串,ByVal POSTdata作为字符串)作为字符串
尺寸RTN值为StringBuilder=新StringBuilder()
Dim isValidParams为布尔值=真
'检查url
如果(URL.Length<10),则
isValidParams=False
抛出新异常(“URL=”“+URL+””不是有效的URL。”)
ElseIf(URL.IndexOf(“:/”)