AnsweredAssumed Answered

Hitachi Content Platform Connection Issues

Question asked by Mert Ulku on Aug 18, 2015

Hello Everyone,

 

I am trying to build an application on C# that starts a connection and writes a file to a HCP server. While trying to do that I am getting a "System.Net.WebException: Operation requested is not allowed. HttpStatus: Forbidden (Forbidden)" error.

 

What may be the problem here? The related code is below:

Thanks!

 

 

ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);

ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate);

 

      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(dest);

      request.Method = WebRequestMethods.Http.Put;

      request.AllowAutoRedirect = false;

      using (Stream dataStream = request.GetRequestStream())

      {    

        using (MemoryStream fileStreamToRead = new MemoryStream(content))

        {

          fileStreamToRead.CopyTo(dataStream); // Copy File stream into Request Stream.

        }

      }

      string sHeader = "HCP " + Base64Encode(HCPUserName) + ":" + MD5Encode(HCPPassword);

      request.Headers.Add("Authorization", sHeader);

      HttpWebResponse response = null;

      try

      { 

        response = (HttpWebResponse)request.GetResponse();

        switch (response.StatusCode)

        {

          case HttpStatusCode.Created:

            break;

          case HttpStatusCode.Found:

            response.Close(); // Clean up response resources.

            throw new WebException("Authentication Failure with HCP. HttpStatus: " + response.StatusCode + " (" + response.StatusDescription + ")");

          default:

            response.Close(); // Clean up response resources.

            throw new WebException("Unexpected HTTP Response Code: " + response.StatusCode + " (" + response.StatusDescription + ")");

        }

        response.Close();      

      }

      catch (WebException ex)

      {

        // If we have a response to interrogate, let's do so.

        if (null != ex.Response)

        {

          HttpWebResponse response2 = (HttpWebResponse)ex.Response;

          HttpStatusCode statusCode = response2.StatusCode;

          String statusDescription = response2.StatusDescription;

          response2.Close(); // Clean up response resources

          response2.Dispose();

          response2 = null;

          switch (statusCode)

          {

            case HttpStatusCode.Conflict:

              throw new WebException("Object already exists on HCP. HttpStatus: " + statusCode + " (" + statusDescription + ")");

            case HttpStatusCode.Forbidden:

              throw new WebException("Operation requested is not allowed. HttpStatus: " + statusCode + " (" + statusDescription + ")");

          }

        }

        throw ex;

Outcomes