Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use method like DELETE #28

Closed
GabMgt opened this issue Nov 25, 2014 · 2 comments
Closed

Use method like DELETE #28

GabMgt opened this issue Nov 25, 2014 · 2 comments

Comments

@GabMgt
Copy link

GabMgt commented Nov 25, 2014

Hello, it's me again !

I can not find how to use a custom HTTP method.
I use your libcurl bind to communicate with an API and I need to send GET,POST,PUT,DELETE and HEAD HTTP requests please.

@andelf
Copy link
Owner

andelf commented Nov 26, 2014

You've asked a libcurl question.

USE curl.OPT_CUSTOMREQUEST options to customize HTTP request method.

package main

import (
  "fmt"
  curl "github.com/andelf/go-curl"
)

func main() {
  easy := curl.EasyInit()
  defer easy.Cleanup()
  easy.Setopt(curl.OPT_URL, "http://httpbin.org/")
  easy.Setopt(curl.OPT_CUSTOMREQUEST, "OPTIONS")
  // make a callback function
  fooTest := func (buf []byte, userdata interface{}) bool {
    println("DEBUG: size=>", len(buf))
    println("DEBUG: content=>", string(buf))
        return true
  }

  easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)
  // for OPTIONS response, we use HEADERFUNCTION to fetch
  easy.Setopt(curl.OPT_HEADERFUNCTION, fooTest)

  if err := easy.Perform(); err != nil {
    fmt.Printf("ERROR: %v\n", err)
  }
}

You will got

DEBUG: content=> Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS

in your output. :)

@GabMgt
Copy link
Author

GabMgt commented Nov 26, 2014

It's working! Thank you!

@GabMgt GabMgt closed this as completed Nov 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants