diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index a8ccf2b9a..698f29c56 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -1,5 +1,6 @@ class HomeworkCommonController < ApplicationController require 'net/http' + require 'json' layout "base_courses" before_filter :find_course, :only => [:index,:new,:create,:next_step] before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy] @@ -74,7 +75,6 @@ class HomeworkCommonController < ApplicationController homework_detail_programing.standard_code = params[:standard_code] question = {title:homework.name,content:homework.description} - uri = URI('http://test.gitlab.trustie.net/api/questions.json') question[:input] = [] question[:output] = [] if params[:input] && params[:output] @@ -89,7 +89,22 @@ class HomeworkCommonController < ApplicationController end end end - res = Net::HTTP.post_form(uri, question) + + # uri = URI('http://test.gitlab.trustie.net/api/questions.json') + # req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'}) + # req.body = question.to_json + # res = Net::HTTP.start(uri.hostname, uri.port) do |http| + # http.request(req) + # end + + uri = URI('http://test.gitlab.trustie.net/api/questions.json') + body = question.to_json + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Post.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end result = JSON.parse(res.body) homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0 diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 0168e1057..2d8403fa2 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -122,13 +122,19 @@ class StudentWorkController < ApplicationController if stundet_work.save if @homework.homework_type == 2 && @homework.homework_detail_programing #编程作业,学生提交作品后计算系统得分 url = "http://test.gitlab.trustie.net/api/questions/#{@homework.homework_detail_programing.question_id}/solutions.json" - uri = URI(url) solutions = { stundet_work_id:stundet_work.id, src:stundet_work.description, language:1 } - Net::HTTP.post_form(uri, solutions) + uri = URI(url) + body = solutions.to_json + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Post.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end end respond_to do |format| format.html {