Results 1 to 4 of 4

Thread: Reading post variables in HTTPProvider

  1. #1
    Join Date
    Feb 2013
    Posts
    18

    Default Reading post variables in HTTPProvider

    I'm making a simple post API plugin but am having some difficulty reading information that is POSTed to the server. I need to be able to read the values from the 'form-data' content-disposition header, not only x-www-form-urlencoded data. I cant use anything that works with query strings because the servers are within a CDN that either strips the query strings or it will cache the request.

    My code so far:
    public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
    		if (!doHTTPAuthentication(vhost, req, resp))
    			return;
    		
    		if (req.getMethod().equalsIgnoreCase("post")) {
    			req.parseBodyForParams(true);
    		}
    		
    		Map<String, List<String>> params = req.getParameterMap();
    		String streamName = "", dvrRecorder = "", outputData = "";
    		
    		if(params.containsKey("stream_name"))
    			streamName = params.get("stream_name").get(0);
    		else
    			outputData += "Field stream_name is required\n";
    		
    		if(params.containsKey("dvr_recorder"))
    			streamName = params.get("dvr_recorder").get(0);
    		else
    			outputData += "Field dvr_recorder is required\n";
    }
    If I use Postman chrome extension to test, I get both of my error messages if I use the form-data method. I can read the data if POSTed using x-www-form-urlencoded method, but like I said I cant use that.

    Is there something I'm missing?

  2. #2
    Join Date
    May 2013
    Posts
    680

    Default

    There isn't really a convenience function to handle multipart form-data post parameters. You'll have to look into the value of content-type to get the boundary:

    String boundary = "";
    if(req.getContentType().startsWith("multipart") )
    {
         boundary = req.getContentType().split("=")[1];
    }
    Then parse out the input stream based on the boundary as everything will be contained by the boundary delimiters:

    req.getInputStream();
    To obtain the posted data.

  3. #3
    Join Date
    Feb 2013
    Posts
    18

    Default

    Quote Originally Posted by matt_y View Post
    There isn't really a convenience function to handle multipart form-data post parameters. You'll have to look into the value of content-type to get the boundary:

    String boundary = "";
    if(req.getContentType().startsWith("multipart") )
    {
         boundary = req.getContentType().split("=")[1];
    }
    Then parse out the input stream based on the boundary as everything will be contained by the boundary delimiters:

    req.getInputStream();
    To obtain the posted data.
    Thanks, that helped a lot!
    EDIT: I was able to get the boundary, however it doesnt seem like there is any delimiter. The entire Content-type section is this:
    multipart/form-data; boundary=----WebKitFormBoundary2IVRpk4adX0fOrmC
    Maybe im still missing something.

    One more unrelated question: What value exactly is the function
    DvrManifestEntryRangeGroup rangeGroup = manifest.getEntriesToPurge(LONG);
    expecting as a LONG? I've tried several numbers but they dont seem to match anything and none of my DVR manifest is cleared. Are there examples of this function anywhere?
    Last edited by ablankenship; 10-04-2013 at 06:08 AM.

  4. #4
    Join Date
    May 2013
    Posts
    680

    Default

    Its a bit of a tough one to parse. You can use the boundary as the initial parsing string but then you'll need to work out the name/value pairs etc.

    As far as getEntriesToPurge, it expects a time as a long value (as you've indicated).

    The work flow is that you pass in a time and the resultant value will be a group of items that would be purged when the time is reached. You could purge them early, if your workflow requires, by passing the items to purgeEntries prior to the time being reached.

Similar Threads

  1. HTTPProvider for reading log files.
    By fly135 in forum Server Administration
    Replies: 2
    Last Post: 09-08-2014, 08:42 AM
  2. Custom module to stop stream from post variables
    By FrankTrog in forum Wowza Streaming Server Java API
    Replies: 8
    Last Post: 05-06-2014, 12:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •