Archived Forum Post

Index of archived forum posts

Question:

Upload to Onedrive

Apr 12 '17 at 12:34

I am trying to upload a file to a shared onedrive folder using rest. the link begins with "https://1drv.ms//f//s!A.... the lasterrortext is

/
ChilkatLog:
  Connect(15ms):
    DllDate: Mar 23 2017
    ChilkatVersion: 9.5.0.66
    UnlockPrefix: Anything for 30-day trial
    Architecture: Little Endian; 64-bit
    Language: .NET 4.5 / x64
    VerboseLogging: 1
    socket2Connect(15ms):
      connect2(15ms):
        hostname: https://1drv.ms//f//s!A...
        port: 433
        ssl: 1
        connectImplicitSsl:
          Clearing TLS client certificates.
          connectSocket:
            domainOrIpAddress: https://1drv.ms//f//s!A...
            port: 433
            connectTimeoutMs: 30000
            connect_ipv6_or_ipv4:
              Multi-threaded domain to IP address resolution
              resolveHostname6:
                getAddressInfo:
                  Failed to get host address info. (3)
                  SocketError: WSAHOST_NOT_FOUND No such host is known.

              hostOrIpAddr: 1drv.msfs!A....
              **This is missing the / on either side of the f**

              port: 433
              Versions of Windows earlier than Windows XP are limited to handling IPv4 only
              On Windows Server 2003 and Windows XP, IPv6 addresses are returned only if IPv6 is installed on the local computer.
            --getAddressInfo
          --resolveHostname6
          Domain to IP address resolution failed.
        --connect_ipv6_or_ipv4
      --connectSocket
      pmConnect failed.
    --connectImplicitSsl
    ConnectFailReason: DNS lookup failed
  --connect2
--socket2Connect
Failed.

--Connect --ChilkatLog


Answer

Thanks! The Connect method expects a domain name or IP address to be passed to it. You passed "https://1drv.ms//f//s!A...", which is the full URL. You should instead pass only "1drv.ms" which is the domain part of the URL.


Answer

Ok it is now connecting. Here is my code:

       string myonedrive = "/f/";
        string remoteuri = "https://1drv.ms/f/s!AvS4YOUC92...";
        string fileName = "C:\\WITS TS\\weightags\\witsxaf.txt"; 
        byte[] bites = System.IO.File.ReadAllBytes(fileName);

        Chilkat.Global glob = new Chilkat.Global();
        bool success = glob.UnlockBundle("Anything for 30-day trial");

        //WebClient myclient = new WebClient();
        //myclient.UploadFile(remoteuri, fileName);

        //myclient.UploadData(remoteuri, "PUT", bites);

        Chilkat.Rest rest = new Chilkat.Rest();

        rest.VerboseLogging = true;
        rest.AddHeader("Content-Type", "application/octet-stream");
        success = rest.AddHeader("content-disposition", "form-data; name = file ; filename="+fileName+'"');
        rest.AddHeader("Authorization", "s!AvS4YOUC92....");
        success = rest.Connect("1drv.ms", 443, true, true);

        Chilkat.Stream filestrem = new Stream();
        filestrem.SourceFile = fileName;

        string responsestr = rest.FullRequestStream("PUT", myonedrive , filestrem);

But I am getting the following error:

/
ChilkatLog:
  FullRequestStream(79ms):
    DllDate: Mar 23 2017
    ChilkatVersion: 9.5.0.66
    UnlockPrefix: Anything for 30-day trial
    Architecture: Little Endian; 64-bit
    Language: .NET 4.5 / x64
    VerboseLogging: 1
    sendReqStreamBody:
      sendReqStreamNC:
        sendReqStreamNonChunked:
          sendReqHeader:
            uriPath: /f/
            constructStartLine:
              uriPath: /f/
            --constructStartLine
            getMimeHeaderHttp:
              headerField: Host: 1drv.ms
              headerField: Content-Type: application/octet-stream
              headerField: content-disposition: form-data; name =file; filename="C:WITS TSweightagswitsxaf.txt"
              headerField: Authorization: s!AvS4YOUC92....
              headerField: Content-Length: 469
            --getMimeHeaderHttp
            requestHeader: [PUT /f/ HTTP/1.1
Host: 1drv.ms
Content-Type: application/octet-stream
content-disposition: form-data; name =file; filename="C:WITS TSweightagswitsxaf.txt"
Authorization: s!AvS4YOUC92....
Content-Length: 469

] --sendReqHeader --sendReqStreamNonChunked --sendReqStreamNC --sendReqStreamBody fullRequestGetResponse(79ms): Reading response header... responseHeader: [HTTP/1.1 405 Method Not Allowed Content-Length: 103 Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/8.5 X-MSNSERVER: DM5SCH102220908 Strict-Transport-Security: max-age=31536000; includeSubDomains X-QosStats: {"ApiId":0,"ResultType":2,"SourcePropertyId":0,"TargetPropertyId":42} X-ThrowSite: 4d6d.dbc6 X-AsmVersion: UNKNOWN; 22.1.0.0 X-MSEdge-Ref: Ref A: 67A3CBEAE8464A7A83A5A92582510BDD Ref B: PAOEDGE0419 Ref C: Wed Apr 12 09:15:54 2017 PST Date: Wed, 12 Apr 2017 16:15:54 GMT

] responseStatusCode: 405 Reading response body... --fullRequestGetResponse Success. --FullRequestStream --ChilkatLog

I get the same error 405 when trying to use webclient.


Answer

I'll try to get some examples out in the next few days..