title: Create http request to upload and get file from s3 base api gateway aws
body: <p>I have made a method to request API Gateway AWS to PUT and load to upload a binary file to s3. </p>
  
  <p>I have created some common methods to create Authorization header like this <a href="https://forums.aws.amazon.com/thread.jspa?messageID=819688" rel="nofollow noreferrer">https://forums.aws.amazon.com/thread.jspa?messageID=819688</a></p>
  
  <p>my example api link like this: <a href="https://xxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/api/bucket/file.txt" rel="nofollow noreferrer">https://xxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/api/bucket/file.txt</a></p>
  
  <pre><code>string[] uriSplit = urlApi.Split('/');              
              string host = uriSplit[2];
              string canonicalUri ="/" + uriSplit[3];               
              string hashedRequestPayload = Utils.CreateRequestPayload(dataFile);
  
              string authorization = Utils.Sign(hashedRequestPayload, "PUT", canonicalUri, string.Empty,
                                                ContentType.ApplicationOctetStream, AWSRegionName.AsiaPacificTokyo,
                                                AWSCommon.APIGateWayServiceName, host);
              string requestDate = DateTime.UtcNow.ToString("yyyyMMddTHHmmss") + "Z";
  
              WebRequest request = WebRequest.Create(urlApi);
  
              request.Timeout = timeout;
              request.Method = "PUT";
              request.ContentType = ContentType.ApplicationOctetStream;
              request.Headers.Add("X-Amz-Date", requestDate);
              request.Headers.Add("Authorization", authorization);                
  
              using (var requestStream = request.GetRequestStream())
              {
                  requestStream.Write(dataFile, 0, dataFile.Length);
              }
  
              // GetResponse
              using (WebResponse response = request.GetResponse())
              {
                  var responseStream = response.GetResponseStream();
                  if (responseStream != null &amp;&amp; responseStream.CanRead)
                  {
                      // Get response WebResponse
                      using (StreamReader reader = new StreamReader(responseStream))
                      {
                          // Parse to string result
                          result = reader.ReadToEnd();
                      }
                  }
                  return ((HttpWebResponse)response).StatusCode;
              }
  </code></pre>
  
  <p>I always receive status code 403 servers forbidden.
  How can I create the canonicalUri and canonicalQueryString base the request URL?</p>
  
  <p>and what I mistake to create the HTTP request to API gateway AWS?</p>