Windows.Web.Http.HttpClient帖子发送特殊字符(从客户端检测到潜在危险的Request.Form值)

时间:2018-08-21 08:54:56

标签: c# uwp asp.net-mvc-2 httpclient

我需要将以下文本发送到Web应用程序(MVC2)

  

你好<>〜!@#$%^&*()_ + |} {“:?> << / p>      

你好<>?:: P {{} | +)_)_&*()&^ * ^%&#%^ @#$〜!@#〜!@#〜Q

我正在使用Windows.Web.Http.HttpClient通过UWP应用发送此消息。但是,当从网上收到此消息时,它将引发异常。

  

“从客户端检测到一个潜在危险的Request.Form值(数据=” ..._&*()&^ * ^%&#%^ @#$〜!@#〜!@#〜Q“ )。”

Android和iOS应用程序可以发送相同的消息,并且Web服务器可以毫无问题地接受该消息。有人可以在没有服务器端任何修改的情况下帮助我解决此问题吗?

这是我在UWP应用上使用的代码。如果需要任何更改,请告诉我。再次感谢。

// MARK : resets XMPPFileTransfer objects' setting.
func resetXMPPFileTransferSettings(){

    incomingFileTransfer.disableSOCKS5 = false
    incomingFileTransfer.disableIBB = false
    incomingFileTransfer.disableDirectTransfers = false
    outgoingFileTransfer.disableSOCKS5 = false
    outgoingFileTransfer.disableIBB = false
    outgoingFileTransfer.disableDirectTransfers = false
}

// Used for sending a file
func sendFile(_ file: Data, to user: XMPPJID) {

    resetXMPPFileTransferSettings()

    outgoingFileTransfer.recipientJID = user

    do{
        try outgoingFileTransfer.send(file, named: nil, toRecipient: user, description: nil)
        loadingAlert.title = "Sending"
        loadingAlert.message = "Please wait..."
        loadingAlert.show(completion: nil)
    }catch{
        ...
    }
}

func xmppIncomingFileTransfer(_ sender: XMPPIncomingFileTransfer!, didReceiveSIOffer offer: XMPPIQ!) {
    sender.acceptSIOffer(offer)
}

func xmppIncomingFileTransfer(_ sender: XMPPIncomingFileTransfer!, didSucceedWith data: Data!, named name: String!) {
    resetXMPPFileTransferSettings()
}

func xmppIncomingFileTransfer(_ sender: XMPPIncomingFileTransfer!, didFailWithError error: Error!) {
    resetXMPPFileTransferSettings()
}

func xmppOutgoingFileTransferDidSucceed(_ sender: XMPPOutgoingFileTransfer!) {

    loadingAlert.title = "succeed!"
    loadingAlert.message = "File successfully transferred."
    DispatchQueue.main.asyncAfter(deadline: .now()+1.875) {
        self.loadingAlert.dismiss(animated: true)
    }
    resetXMPPFileTransferSettings()
}

func xmppOutgoingFileTransfer(_ sender: XMPPOutgoingFileTransfer!, didFailWithError error: Error!) {

    loadingAlert.dismiss(animated: true)
    let alert = UIAlertController(title: "Failed!", message: "Check the logs..", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "close", style: .cancel, handler: nil))
    alert.addAction(UIAlertAction(title: "log", style: .default, handler: { _ in
        ...
    }))

    present(alert, animated: true, completion: nil)

    resetXMPPFileTransferSettings()
}

func xmppOutgoingFileTransferIBBClosed(_ sender: XMPPOutgoingFileTransfer!) {
}

0 个答案:

没有答案