小编use*_*346的帖子

WebRequest不发送客户端证书

我正在为REST API编写客户端并对API进行身份验证我必须使用提供给我的证书.

这段代码如下:

public string GetCustomer(int custId)
{
X509Certificate2 Cert = new X509Certificate2();
    Cert.Import(@"C:\users\foo\desktop\api\pubAndPrivateCert.pkcs12", "", X509KeyStorageFlags.PersistKeySet);

    ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://api.foo.net/api/customer/v1/" + custId);
    req.ClientCertificates.Add(Cert);

    req.UserAgent = "LOL API Client";
    req.Accept = "application/json";
    req.Method = WebRequestMethods.Http.Get;

    string result = null;
    using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
StreamReader reader = new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
return result;
}
Run Code Online (Sandbox Code Playgroud)

每次我发出请求时都会收到错误400,当使用Fiddler查看响应时,我得到以下内容

<html>
<head><title>400 No required SSL certificate was sent</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>No required SSL certificate was sent</center>
<hr><center>nginx/0.6.32</center> …
Run Code Online (Sandbox Code Playgroud)

c# rest ssl

8
推荐指数
1
解决办法
2万
查看次数

ctypes并通过引用传递给函数

我正在尝试使用ctypes在python3中使用libpcap.

在C中给出以下功能

pcap_lookupnet(dev, &net, &mask, errbuf)
Run Code Online (Sandbox Code Playgroud)

在python我有以下内容

pcap_lookupnet = pcap.pcap_lookupnet

mask = ctypes.c_uint32
net = ctypes.c_int32

if(pcap_lookupnet(dev,net,mask,errbuf) == -1):
print("Error could not get netmask for device {0}".format(errbuf))
sys.exit(0)
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

  File "./libpcap.py", line 63, in <module>
 if(pcap_lookupnet(dev,net,mask,errbuf) == -1):
ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2
Run Code Online (Sandbox Code Playgroud)

你如何应对&blah价值观?

python ctypes libpcap

7
推荐指数
1
解决办法
1万
查看次数

将对象集中到Azure Blob存储

我试图将对象写入azure blob以进行持久存储,并且由于某种原因,1属性从未被序列化,我不确定为什么.

这是对象

[Serializable]
public class BlobMetaData
{
    public DateTimeOffset? ModifiedDate { get; set; }
    public string ContentType { get; set; }
    public string Name { get; set; }
    // size of the file in bytes
    public long Length { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是将数据保存到Azure存储的功能.

public void Save(string filename,BlobProperties blobProperties)
{
    //full path to the blob
    string saveFile = _clientDirectory + filename;
    CloudBlockBlob blockBlob = _blobContainer.GetBlockBlobReference(saveFile);
    //blobMetaData properly gets all the right values.
    BlobMetaData blobMetaData = ConvertBlobProperties(blobProperties,filename);
    // I convert …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-storage-blobs

3
推荐指数
1
解决办法
1715
查看次数

标签 统计

c# ×2

azure ×1

azure-storage-blobs ×1

ctypes ×1

libpcap ×1

python ×1

rest ×1

ssl ×1