responseTextは、値が設定されているのにresponseXMLに値が設定されないのはなぜ?


野菜くん  2006-12-22 01:23:43  No: 97492

responseTextには、値が設定されているのにresponseXMLに値が設定されて
いないのはなぜでしょうか?

原因として何が考えられるでしょう?

↓↓↓<実行モジュール>↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

Dim domDoc  As New MSXML2.DOMDocument
Dim domDoc2 As NEW MSXML2.DOMDocument
Dim xmlHttp As New MSXML2.XMLHTTP

If Not domDoc.Load("D:Sample.xml") Then
    Exit Sub
End If

xmlHttp.open "POST", "http://localhost/sample/sample01.jsp", False
xmlHttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
xmlHttp.setRequestHeader "Content-Length", Len(domDoc.xml)
xmlHttp.send doc.xml

If xmlHttp.Status <> 200 Then
    MsgBox "Error :" & xmlHttp.Status & " " & xmlHttp.statusText
    Exit Sub
End If

Set domDoc2 = xmlHttp.responseXML

RichTextBox1.Text = xmlHttp.responseText
RichTextBox2.Text = retXml.xml

↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑


魔界の仮面弁士  2006-12-22 03:08:40  No: 97493

サーバから返される Content-Type と Charset を確認してみてください。


野菜くん  2006-12-22 18:27:58  No: 97494

回答ありがとうございました。

ただ、私の知識不足で回答いただいた内容の意味がよくわかりません。

サーバ側にどのような設定がされていればよいのでしょうか?


魔界の仮面弁士  2006-12-22 23:38:34  No: 97495

> サーバ側にどのような設定がされていればよいのでしょうか?
具体的な設定方法はサーバの種類によって異なりますので、
詳しくは書きませんが、要は responseXML プロパティの解説に

http://msdn2.microsoft.com/en-us/library/ms757055.aspx

If the response was generated by an ASP page and the MIME type was not correctly set to "text/xml" or "application/xml" using the ASP method Response.ContentType, responseXML will be empty.

……と書かれているように、Content-Type として、適切な MIME タイプが
設定されていなければ、プロパティの中身が空になってしまうという事です。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加