1

エンコードせずにhttpリクエストを送信する必要があります(URLをエンコードすると壊れてしまう愚かなサプライヤーAPIを消費する必要があります)

だから現在私は持っています

    string address = "https://www.eco-bb.bt.com/bbxml33/batchstatus.asp?b_customerId=[O/M12346800]&batchid=[" + batchID + "]";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

生成する

POST https://www.eco-bb.bt.com/bbxml33/Upload.asp?b_customerId=%5BO/M12346800%5D

そして私はそれを生み出して欲しい

POST https://www.eco-bb.bt.com/bbxml33/Upload.asp?b_customerId=[O/M12346800]

私は少し困惑しています。続行する方法について何か提案はありますか?

4

3 に答える 3

3

これを試してみてください。オブジェクトを作成しUri、コンストラクターに文字列を既にエスケープしたことを約束します(これは:pではありません)。

string address = "https://www.eco-bb.bt.com/bbxml33/batchstatus.asp?b_customerId=[O/M12346800]&batchid=[" + batchID + "]";
Uri uri = new Uri(address, true);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); 
于 2012-07-27T17:28:44.830 に答える
2

.NET 4以降を実行している場合は、次の構成を追加できます

<configuration>
  <uri>
    <schemeSettings>
      <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
    </schemeSettings>
  </uri>
</configuration>
于 2012-07-27T18:03:12.180 に答える
0

恐竜である私は、昔は特殊文字を独自の名前に置き換えてサーバー側で解析することにより、URLデータを手動でエンコードすることがあったことを思い出しました。これがサプライヤがWebアプリを構築した方法である場合、サプライヤはどのような特殊文字の置換を期待しているかを通知する必要があります。

http://www.this.com?variable=[12] 

として期待されるかもしれません;

http://www.this.com?variable=lBracket12rBracket

余談ですが、HTTPSを使用せずにサービスを呼び出すと、いくつかの興味深いJavaScript関数が生成されます。

 <script> 
   function Homepage(){
<!--
// in real bits, urls get returned to our script like this:
// res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm 

    //For testing use DocURL = "res://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm"
    DocURL=document.URL;

    //this is where the http or https will be, as found by searching for :// but skipping the res://
    protocolIndex=DocURL.indexOf("://",4);

    //this finds the ending slash for the domain server 
    serverIndex=DocURL.indexOf("/",protocolIndex + 3);

    //for the href, we need a valid URL to the domain. We search for the # symbol to find the begining 
    //of the true URL, and add 1 to skip it - this is the BeginURL value. We use serverIndex as the end marker.
    //urlresult=DocURL.substring(protocolIndex - 4,serverIndex);
    BeginURL=DocURL.indexOf("#",1) + 1;
    urlresult=DocURL.substring(BeginURL,serverIndex);

    //for display, we need to skip after http://, and go to the next slash
    displayresult=DocURL.substring(protocolIndex + 3 ,serverIndex);
    InsertElementAnchor(urlresult, displayresult);
}

function HtmlEncode(text)
{
    return text.replace(/&/g, '&amp').replace(/'/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

function TagAttrib(name, value)
{
    return ' '+name+'="'+HtmlEncode(value)+'"';
}

function PrintTag(tagName, needCloseTag, attrib, inner){
    document.write( '<' + tagName + attrib + '>' + HtmlEncode(inner) );
    if (needCloseTag) document.write( '</' + tagName +'>' );
}

function URI(href)
{
    IEVer = window.navigator.appVersion;
    IEVer = IEVer.substr( IEVer.indexOf('MSIE') + 5, 3 );

    return (IEVer.charAt(1)=='.' && IEVer >= '5.5') ?
        encodeURI(href) :
        escape(href).replace(/%3A/g, ':').replace(/%3B/g, ';');
}

function InsertElementAnchor(href, text)
{
    PrintTag('A', true, TagAttrib('HREF', URI(href)), text);
}

//-->
</script>
于 2012-07-27T17:56:07.580 に答える