Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb6 Webclient.Headers上的自动化错误_Vb6 - Fatal编程技术网

Vb6 Webclient.Headers上的自动化错误

Vb6 Webclient.Headers上的自动化错误,vb6,Vb6,使用Headers属性时,以下代码中出现错误: Public Function UploadImage(image As String) As String Dim wc As System.WebClient 'create WebClient Set wc = CreateObject("System.Net.WebClient") Call wc.Headers.Add("Authorization", "Client-ID " & ClientId) <------

使用Headers属性时,以下代码中出现错误:

Public Function UploadImage(image As String) As String

Dim wc As System.WebClient

'create WebClient

Set wc = CreateObject("System.Net.WebClient")

Call wc.Headers.Add("Authorization", "Client-ID " & ClientId) <------- Error occurs here

我已经尽可能地重新考虑了你的问题。你没有提到你的错误是什么,但我得到了:

Automation error -2146233079   (80131509)
我试着用

CallByName(wc, "Headers", VbGet)
。。。但这一切又回来了

Automation error 440.
哦,好吧

我在网上查了一下,发现。我的猜测是,因为WebHeaderCollection类的基类是不可见的,这导致了错误

我的工作是将此功能封装在一个小的.NET组件中,并使COM可见

例如:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;

namespace WebClientWrapper
{
    [ComVisible(true)]
    [Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]
    public class WebClientWrapper : WebClient
    {
        [ComVisible(true)]
        public WebHeaderCollectionWrapper WHeaders
        {
            get 
            {
                return new WebHeaderCollectionWrapper(base.Headers);
            }
        }
    }

    [ComVisible(true)]
    [Guid("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy")]
    public class WebHeaderCollectionWrapper
    {
        WebHeaderCollection _whc;

        internal WebHeaderCollectionWrapper(WebHeaderCollection whc)
        {
            _whc = whc;
        }

        [ComVisible(true)]
        public void Add(string name, string value)
        {
            _whc.Add(name, value);
        }

        [ComVisible(true)]
        public void Clear()
        {
            _whc.Clear();
        }
    }
}
您必须用自己的值替换GUID-使用GUIDGEN.EXE

使用CreateObjectWebClientWrapper.WebClientWrapper实例化此组件

现在,您只需将对Headers属性的引用替换为WHeaders或任何您想要调用它的内容。WHeaders为WebHeaderCollection提供了一个真正的包装器—您必须自己定义所有其他包装的方法和属性。我希望将Wheader定义为公共WebHeaderCollectionWrapper,但这似乎不起作用

由于WebClient Rapper继承自WebClient,因此您应该能够使用大多数属性和方法。如果您遇到问题,只需向类中添加新方法,即可包装与VB不兼容的功能


哦,请记住在projectproperties=>Build=>Output=>registerforcomuinterop处设置复选框。然后引用创建的类型库。

显示的是什么类型的问题?你想要实现什么?那么我如何让它可见?我真的需要它在vb6中使用我的应用程序