0

着信 Content-Type が明示的であることを期待するサードパーティ ソフトウェアがあります。

application/x-www-form-urlencoded

ただし、以下の ASP スクリプトでは、要求ヘッダーを適切に設定しても、ASP は実際には次のように送信しています。

application/x-www-form-urlencoded; 文字セット=utf-8

その結果、認証が失敗し、サードパーティであるため、将来の更新で変更が上書きされる可能性があるため、自分でパッチを適用する自由がない場合があります.

Content-type を明示的に強制し、"; charset=utf-8" が追加されないようにするにはどうすればよいでしょうか?

<%
'IRISLink.cgi expects application/x-www-form-urlencoded

Dim obHTTP
obHTTP.open "POST", "https://" & DWHost & "/IRISLink.cgi", False

obHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
obHTTP.Send strPost
Set obHTTP = Nothing

'Failure - Actual Content-type received was: application/x-www-form-urlencoded; charset=utf-8
%>
4

2 に答える 2

1

どのオブジェクトを使用しているのか正確にはわかりませんが、私のテストに基づいて、MSXML2.ServerXMLHTTP. これは通常、MSXML 3.0 バージョンを指します。比較的簡単な修正方法の 1 つは、たとえばMSXML2.ServerXMLHTTP.6.0.

何らかの理由でそれが不可能な場合は、文字列の代わりにADODB.Streamオブジェクトをメソッドに渡すことができます。sendこの例については、私のテスト スクリプトを参照してください。

テスト スクリプト:

Option Explicit

Dim strPost
strPost = "Testing 1,2,3"

Dim oStream
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 2 ' adTypeText
oStream.Charset = "UTF-8" ' or whatever charset the 3rd party app requires
oStream.WriteText strPost

' skip UTF-8 BOM (see http://stackoverflow.com/questions/4143524)
' If you're using a different charset, you should set Position to 0
oStream.Position = 3

Dim oHttp
Set oHttp = CreateObject("Msxml2.ServerXMLHTTP")
oHttp.open "POST", "http://example.com/", False

oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHttp.send oStream
'oHttp.send strPost
oStream.Close
于 2013-09-30T06:47:41.840 に答える
0

これは従来の ASP の制限であり、回避できないようです。この同じコードを C# に移植すると、Content-type は指定されたとおりに文字どおりに受信されますが、ASP では受信されません。

于 2013-09-27T23:09:40.717 に答える