1

イメージを REST Web ページにアップロードしようとしています。cURL 呼び出しを使用して、これを正常に実行できます。

curl -u Admin:admin -T C:\temp\wikiTable.jpg http://192.168.0.35:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/attachments/table.jpg

私は現在、Excel vba の HTTP Post を使用してこれを達成しようとしていますが、いくつかの問題が発生しています。私は現在これをやっています:

Const STR_BOUNDARY  As String = "---------------------------123456789abc"
Dim nFile           As Integer
Dim baBuffer()      As Byte
Dim sPostData       As String
Dim sFileName       As String
Dim sUrl            As String
sFileName =  "C:\temp\wikiTable.jpg"  
sUrl =  "http://192.168.0.35:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/attachments/table.jpg"     
'--- read file
nFile = FreeFile
Open sFileName For Binary Access Read As nFile
If LOF(nFile) > 0 Then
    ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
    Get nFile, , baBuffer
    sPostData = StrConv(baBuffer, vbUnicode)
End If
Close nFile
'-- post
Dim HTTPReq As Object
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HTTPReq.Option(4) = 13056
HTTPReq.Open "Post", sUrl, False
HTTPReq.SetCredentials "Admin", "admin", 0
HTTPReq.setRequestHeader "Content-Type: multipart/form-data;"
HTTPReq.send sPostData
MsgBox (HTTPReq.responseText)

responseText については、次のエラーが発生し続けます。

10.4.6 405 Method Not Allowed

The method specified in the Request-Line is not allowed for the resource 
identified by the Request-URI. The response MUST include an Allow header 
containing a list of valid methods for the requested resource.
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6

ここで私が間違っていることはありますか?

4

2 に答える 2